From 501540c76e32abb5ae49d1c3e9730b63eb38aa4c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 17 Jan 2017 14:25:04 -0800 Subject: [PATCH] Use the list of Content files specified in the project as a source Fixes #59 --- RazorViewCompilation.sln | 20 +-- build/common.props | 7 +- .../Internal/CompilationOptions.cs | 15 ++- .../Internal/MvcServiceProvider.cs | 3 - .../Internal/PrecompileRunCommand.cs | 40 +++--- .../Internal/ViewCompilationInfo.cs | 7 +- .../Internal/ViewFileInfo.cs | 34 +++++ .../ViewInfoContainerCodeGenerator.cs | 2 +- ...spNetCore.Mvc.Razor.ViewCompilation.csproj | 2 - .../build/common.targets | 54 ++++---- ...pNetCore.Mvc.Razor.ViewCompilation.targets | 9 +- ...pNetCore.Mvc.Razor.ViewCompilation.targets | 5 +- .../ApplicationWithCustomInputFilesTest.cs | 118 ++++++++++++++++++ ...zor.ViewCompilation.FunctionalTests.csproj | 5 +- .../PublishWithEmbedViewSourcesTest.cs | 6 +- ...mingPrecompiledViews.Manage.Home.Index.txt | 2 +- ...ApplicationWithConfigureMvc.Home.Index.txt | 2 +- ...hTagHelpers.Home.ClassLibraryTagHelper.txt | 4 +- ...tionWithTagHelpers.Home.LocalTagHelper.txt | 4 +- .../SimpleAppDesktopOnly.Home.Index.txt | 4 +- .../Resources/SimpleAppTest.Home.Index.txt | 4 +- .../Resources/StrongNamedApp.Home.Index.txt | 2 +- ...Core.Mvc.Razor.ViewCompilation.Test.csproj | 4 - .../PrecompileRunCommandTest.cs | 9 +- .../ApplicationWithCustomInputFiles.csproj | 26 ++++ .../Controllers/HomeController.cs | 23 ++++ .../Program.cs | 26 ++++ .../Startup.cs | 26 ++++ .../Views/Home/About.cshtml | 1 + .../Views/Home/Index.cshtml | 1 + .../Views/Home/NotIncluded.cshtml | 1 + 31 files changed, 366 insertions(+), 100 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithCustomInputFilesTest.cs create mode 100644 testapps/ApplicationWithCustomInputFiles/ApplicationWithCustomInputFiles.csproj create mode 100644 testapps/ApplicationWithCustomInputFiles/Controllers/HomeController.cs create mode 100644 testapps/ApplicationWithCustomInputFiles/Program.cs create mode 100644 testapps/ApplicationWithCustomInputFiles/Startup.cs create mode 100644 testapps/ApplicationWithCustomInputFiles/Views/Home/About.cshtml create mode 100644 testapps/ApplicationWithCustomInputFiles/Views/Home/Index.cshtml create mode 100644 testapps/ApplicationWithCustomInputFiles/Views/Home/NotIncluded.cshtml diff --git a/RazorViewCompilation.sln b/RazorViewCompilation.sln index 6b652d4198..73a67c64d4 100644 --- a/RazorViewCompilation.sln +++ b/RazorViewCompilation.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26014.0 +VisualStudioVersion = 15.0.26118.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation", "src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj", "{4339FC9B-AEC6-442A-B413-A41555ED76C7}" EndProject @@ -19,7 +19,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Ra EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Test", "test\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Test\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Test.csproj", "{E0D75B4E-839F-4F80-9B1F-B33F616BCC5F}" EndProject - +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{87FEE984-F627-4F1E-8995-E5F969B85A19}" + ProjectSection(SolutionItems) = preProject + build\common.props = build\common.props + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -65,18 +69,6 @@ Global {E0D75B4E-839F-4F80-9B1F-B33F616BCC5F}.Release|x64.Build.0 = Release|x64 {E0D75B4E-839F-4F80-9B1F-B33F616BCC5F}.Release|x86.ActiveCfg = Release|x86 {E0D75B4E-839F-4F80-9B1F-B33F616BCC5F}.Release|x86.Build.0 = Release|x86 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Debug|x64.ActiveCfg = Debug|x64 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Debug|x64.Build.0 = Debug|x64 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Debug|x86.ActiveCfg = Debug|x86 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Debug|x86.Build.0 = Debug|x86 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Release|Any CPU.Build.0 = Release|Any CPU - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Release|x64.ActiveCfg = Release|x64 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Release|x64.Build.0 = Release|x64 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Release|x86.ActiveCfg = Release|x86 - {1140C5E1-1C9A-4895-BB7E-C2AB2C320472}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build/common.props b/build/common.props index 1b111f3342..50550ebaf4 100644 --- a/build/common.props +++ b/build/common.props @@ -11,7 +11,12 @@ true - + + + + + + diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs index 6f65d64421..5e7fc24f43 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; using Microsoft.Extensions.CommandLineUtils; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal @@ -15,6 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal public static readonly string PublicSignTemplate = "--public-sign"; public static readonly string ApplicationNameTemplate = "--application-name"; public static readonly string OutputPathTemplate = "--output-path"; + public static readonly string ViewsToCompileTemplate = "--file"; public CompilationOptions(CommandLineApplication app) { @@ -30,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal ProjectArgument = app.Argument( "project", - "The path to the project (project folder or project.json) with precompilation."); + "The path to the project file."); ConfigureCompilationType = app.Option( ConfigureCompilationTypeTemplate, @@ -49,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal KeyFileOption = app.Option( StrongNameKeyPath, - "Strong name key path", + "Strong name key path.", CommandOptionType.SingleValue); DelaySignOption = app.Option( @@ -61,6 +63,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal PublicSignTemplate, "Determines if the precompiled view assembly is to be public signed.", CommandOptionType.NoValue); + + ViewsToCompileOption = app.Option( + ViewsToCompileTemplate, + "Razor files to compile.", + CommandOptionType.MultipleValue); } public CommandArgument ProjectArgument { get; } @@ -81,6 +88,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal public CommandOption ApplicationNameOption { get; } + public CommandOption ViewsToCompileOption { get; } + public string OutputPath => OutputPathOption.Value(); public string ApplicationName => ApplicationNameOption.Value(); @@ -90,5 +99,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal public bool DelaySign => DelaySignOption.HasValue(); public bool PublicSign => PublicSignOption.HasValue(); + + public List ViewsToCompile => ViewsToCompileOption.Values; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs index 1c9146757b..fd26c58907 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs @@ -38,15 +38,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal Host = serviceProvider.GetRequiredService(); Compiler = serviceProvider.GetRequiredService(); ViewEngineOptions = serviceProvider.GetRequiredService>().Value; - FileProvider = serviceProvider.GetRequiredService().FileProvider; } public IMvcRazorHost Host { get; } public CSharpCompiler Compiler { get; } - public IFileProvider FileProvider { get; } - public RazorViewEngineOptions ViewEngineOptions { get; } private IDesignTimeMvcBuilderConfiguration GetConfigureCompilationAction(string configureCompilationType) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs index 2d494eafe5..e5278364a1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.Text; using Microsoft.Extensions.CommandLineUtils; -using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { @@ -109,11 +108,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal var resources = new ResourceDescription[results.Length]; for (var i = 0; i < results.Length; i++) { - var fileInfo = results[i].RelativeFileInfo; + var fileInfo = results[i].ViewFileInfo; resources[i] = new ResourceDescription( - fileInfo.RelativePath.Replace('\\', '/'), - fileInfo.FileInfo.CreateReadStream, + fileInfo.ViewEnginePath, + fileInfo.CreateReadStream, isPublic: true); } @@ -171,9 +170,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { var result = results[i]; var sourceText = SourceText.From(result.GeneratorResults.GeneratedCode, Encoding.UTF8); - var fileInfo = result.RelativeFileInfo; + var fileInfo = result.ViewFileInfo; var syntaxTree = compiler.CreateSyntaxTree(sourceText) - .WithFilePath(fileInfo.FileInfo.PhysicalPath ?? fileInfo.RelativePath); + .WithFilePath(fileInfo.FullPath ?? fileInfo.ViewEnginePath); syntaxTrees[i] = syntaxTree; }); @@ -231,15 +230,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal private ViewCompilationInfo[] GenerateCode() { - var files = new List(); - GetRazorFiles(MvcServiceProvider.FileProvider, files, root: string.Empty); + var files = GetRazorFiles(); var results = new ViewCompilationInfo[files.Count]; Parallel.For(0, results.Length, ParalellOptions, i => { var fileInfo = files[i]; - using (var fileStream = fileInfo.FileInfo.CreateReadStream()) + using (var fileStream = fileInfo.CreateReadStream()) { - var result = MvcServiceProvider.Host.GenerateCode(fileInfo.RelativePath, fileStream); + var result = MvcServiceProvider.Host.GenerateCode(fileInfo.ViewEnginePath, fileStream); results[i] = new ViewCompilationInfo(fileInfo, result); } }); @@ -247,20 +245,24 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal return results; } - private static void GetRazorFiles(IFileProvider fileProvider, List razorFiles, string root) + private List GetRazorFiles() { - foreach (var fileInfo in fileProvider.GetDirectoryContents(root)) + var contentRoot = Options.ContentRootOption.Value(); + var viewFiles = Options.ViewsToCompile; + var relativeFiles = new List(viewFiles.Count); + var trimLength = contentRoot.EndsWith("/") ? contentRoot.Length - 1 : contentRoot.Length; + + for (var i = 0; i < viewFiles.Count; i++) { - var relativePath = Path.Combine(root, fileInfo.Name); - if (fileInfo.IsDirectory) + var fullPath = viewFiles[i]; + if (fullPath.StartsWith(contentRoot, StringComparison.OrdinalIgnoreCase)) { - GetRazorFiles(fileProvider, razorFiles, relativePath); - } - else if (fileInfo.Name.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) - { - razorFiles.Add(new RelativeFileInfo(fileInfo, relativePath)); + var viewEnginePath = fullPath.Substring(trimLength).Replace('\\', '/'); + relativeFiles.Add(new ViewFileInfo(fullPath, viewEnginePath)); } } + + return relativeFiles; } private string ReadTypeInfo(CSharpCompilation compilation, SyntaxTree syntaxTree) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs index 8630b3f456..8ab014365b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Razor.Compilation; using Microsoft.AspNetCore.Razor.CodeGenerators; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal @@ -9,14 +8,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal public class ViewCompilationInfo { public ViewCompilationInfo( - RelativeFileInfo relativeFileInfo, + ViewFileInfo viewFileInfo, GeneratorResults generatorResults) { - RelativeFileInfo = relativeFileInfo; + ViewFileInfo = viewFileInfo; GeneratorResults = generatorResults; } - public RelativeFileInfo RelativeFileInfo { get; } + public ViewFileInfo ViewFileInfo { get; } public GeneratorResults GeneratorResults { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs new file mode 100644 index 0000000000..fe8f1196fc --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal +{ + public struct ViewFileInfo + { + public ViewFileInfo(string fullPath, string viewEnginePath) + { + FullPath = fullPath; + ViewEnginePath = viewEnginePath; + } + + public string FullPath { get; } + + public string ViewEnginePath { get; } + + public Stream CreateReadStream() + { + // We are setting buffer size to 1 to prevent FileStream from allocating it's internal buffer + // 0 causes constructor to throw + var bufferSize = 1; + return new FileStream( + FullPath, + FileMode.Open, + FileAccess.Read, + FileShare.ReadWrite, + bufferSize, + FileOptions.Asynchronous | FileOptions.SequentialScan); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs index 397f2c038e..c00ded2d08 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal var precompiledViewsArray = new StringBuilder(); foreach (var item in result) { - var path = item.RelativeFileInfo.RelativePath; + var path = item.ViewFileInfo.ViewEnginePath; precompiledViewsArray.AppendLine( $"new global::{typeof(ViewInfo).FullName}(@\"{path}\", typeof({item.TypeName})),"); } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj index 74d0bf101d..d5d4740ae6 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj @@ -13,10 +13,8 @@ - - diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets index bcd636d882..7df1e2a00a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets @@ -1,21 +1,19 @@ - - <_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)')) - <_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath) - <_MvcRazorOutputFullPath>$([System.IO.Path]::Combine($(_MvcRazorOutputPath), '$(MSBuildProjectName).PrecompiledViews.dll')) - <_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp + + + <_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)')) + <_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath) + <_MvcRazorOutputFullPath>$(_MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.dll + <_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp - $(MSBuildProjectDirectory) - true - + $(MSBuildProjectDirectory) + true + - - <_MvcRazorContentFiles Include="$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))**\*.cshtml" /> - - + + + + @@ -28,13 +26,15 @@ + + - - @@ -42,17 +42,25 @@ - + + + + + $([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)')) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets index 131edb069b..1dc1bbf2b3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets @@ -6,7 +6,8 @@ @@ -20,7 +21,7 @@ - @@ -28,7 +29,7 @@ Text="Executing Razor view precompilation." Importance="Low" /> - @@ -37,6 +38,6 @@ Importance="High" /> - + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netcoreapp1.1/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netcoreapp1.1/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets index 081a517bc9..a64c41b277 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netcoreapp1.1/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netcoreapp1.1/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets @@ -5,7 +5,8 @@ @@ -21,7 +22,7 @@ Text="Executing Razor view precompilation." Importance="Low" /> - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithCustomInputFilesTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithCustomInputFilesTest.cs new file mode 100644 index 0000000000..8860803e65 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithCustomInputFilesTest.cs @@ -0,0 +1,118 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.IntegrationTesting; +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests +{ + public class ApplicationWithCustomInputFilesTest + : IClassFixture + { + private const string ApplicationName = "ApplicationWithCustomInputFiles"; + + public ApplicationWithCustomInputFilesTest(ApplicationWithCustomInputFilesTestFixture fixture) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public async Task ApplicationWithCustomInputFiles_Works(RuntimeFlavor flavor) + { + var expectedText = "Hello Index!"; + using (var deployer = Fixture.CreateDeployment(flavor)) + { + // Arrange + var deploymentResult = deployer.Deploy(); + + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + deploymentResult.ApplicationBaseUri, + Fixture.Logger); + + // Assert + Assert.Equal(expectedText, response.Trim()); + } + } + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled(RuntimeFlavor flavor) + { + // Arrange + var expectedViews = new[] + { + "/Views/Home/About.cshtml", + "/Views/Home/Index.cshtml", + }; + + using (var deployer = Fixture.CreateDeployment(flavor)) + { + var deploymentResult = deployer.Deploy(); + + // Act + var response2 = await Fixture.HttpClient.GetStringWithRetryAsync( + $"{deploymentResult.ApplicationBaseUri}Home/GetPrecompiledResourceNames", + Fixture.Logger); + + // Assert + var actual = response2.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) + .OrderBy(p => p, StringComparer.OrdinalIgnoreCase); + Assert.Equal(expectedViews, actual); + } + } + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public void MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled(RuntimeFlavor flavor) + { + // Arrange + var viewsNotPublished = new[] + { + "Index.cshtml", + "About.cshtml", + }; + + var viewsPublished = new[] + { + "NotIncluded.cshtml", + }; + + using (var deployer = Fixture.CreateDeployment(flavor)) + { + var deploymentResult = deployer.Deploy(); + var viewsDirectory = Path.Combine(deploymentResult.ContentRoot, "Views", "Home"); + + // Act & Assert + foreach (var file in viewsPublished) + { + var filePath = Path.Combine(viewsDirectory, file); + Assert.True(File.Exists(filePath), $"{filePath} was not published."); + } + + foreach (var file in viewsNotPublished) + { + var filePath = Path.Combine(viewsDirectory, file); + Assert.False(File.Exists(filePath), $"{filePath} was published."); + } + } + } + + public class ApplicationWithCustomInputFilesTestFixture : ApplicationTestFixture + { + public ApplicationWithCustomInputFilesTestFixture() + : base(ApplicationWithCustomInputFilesTest.ApplicationName) + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj index e473a86882..7ccd46bafd 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj @@ -6,10 +6,9 @@ - - + @@ -21,4 +20,4 @@ - + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs index de0157ac58..1ae6b77938 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs @@ -32,9 +32,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests // Arrange var expectedViews = new[] { - "Areas/TestArea/Views/Home/Index.cshtml", - "Views/Home/About.cshtml", - "Views/Home/Index.cshtml", + "/Areas/TestArea/Views/Home/Index.cshtml", + "/Views/Home/About.cshtml", + "/Views/Home/Index.cshtml", }; var expectedText = "Hello Index!"; using (var deployer = Fixture.CreateDeployment(flavor)) diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt index de01ff4f89..a0e0cd1b3b 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt @@ -1,7 +1,7 @@ - AspNetCore.Areas_Manage_Views_Shared__Layout_cshtml, ClassLibraryWithPrecompiledViews.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + AspNetCore._Areas_Manage_Views_Shared__Layout_cshtml, ClassLibraryWithPrecompiledViews.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Admin home page

diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithConfigureMvc.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithConfigureMvc.Home.Index.txt index edb2b9073a..8d6a706cbd 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithConfigureMvc.Home.Index.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithConfigureMvc.Home.Index.txt @@ -1,2 +1,2 @@ -AspNetCore.Views_Home_Index_cshtml, ApplicationWithConfigureMvc.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +AspNetCore._Views_Home_Index_cshtml, ApplicationWithConfigureMvc.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Hello world! \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.ClassLibraryTagHelper.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.ClassLibraryTagHelper.txt index 38c1e2ea7c..9e1587d4bb 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.ClassLibraryTagHelper.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.ClassLibraryTagHelper.txt @@ -8,7 +8,7 @@
-AspNetCore.Views_Home_ClassLibraryTagHelper_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +AspNetCore._Views_Home_ClassLibraryTagHelper_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
To boldy tag that no one has ever tagged before...
@@ -20,6 +20,6 @@ AspNetCore.Views_Home_ClassLibraryTagHelper_cshtml, ApplicationWithTagHelpers.Pr
- AspNetCore.Views_Shared__Layout_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + AspNetCore._Views_Shared__Layout_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.LocalTagHelper.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.LocalTagHelper.txt index c65026eb02..cda9d510a9 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.LocalTagHelper.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationWithTagHelpers.Home.LocalTagHelper.txt @@ -8,7 +8,7 @@
-AspNetCore.Views_Home_LocalTagHelper_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +AspNetCore._Views_Home_LocalTagHelper_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null TestTagHelper content. @@ -20,6 +20,6 @@ AspNetCore.Views_Home_LocalTagHelper_cshtml, ApplicationWithTagHelpers.Precompil
- AspNetCore.Views_Shared__Layout_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + AspNetCore._Views_Shared__Layout_cshtml, ApplicationWithTagHelpers.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppDesktopOnly.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppDesktopOnly.Home.Index.txt index e047f6ed3e..70675c45a5 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppDesktopOnly.Home.Index.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppDesktopOnly.Home.Index.txt @@ -35,7 +35,7 @@
-AspNetCore.Views_Home_Index_cshtml, SimpleAppDesktopOnly.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +AspNetCore._Views_Home_Index_cshtml, SimpleAppDesktopOnly.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

© 2016 - SimpleApp

@@ -54,6 +54,6 @@ AspNetCore.Views_Home_Index_cshtml, SimpleAppDesktopOnly.PrecompiledViews, Versi - AspNetCore.Views_Shared__Layout_cshtml, SimpleAppDesktopOnly.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + AspNetCore._Views_Shared__Layout_cshtml, SimpleAppDesktopOnly.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppTest.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppTest.Home.Index.txt index 6a085c4be8..620d2a25d0 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppTest.Home.Index.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppTest.Home.Index.txt @@ -35,7 +35,7 @@
-AspNetCore.Views_Home_Index_cshtml, SimpleApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +AspNetCore._Views_Home_Index_cshtml, SimpleApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null