Use the list of Content files specified in the project as a source
Fixes #59
This commit is contained in:
Родитель
c1ef1e533f
Коммит
501540c76e
|
@ -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
|
||||
|
|
|
@ -11,7 +11,12 @@
|
|||
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Workaround for RC3 VS -->
|
||||
<ItemGroup Condition="'$(BuildingInsideVisualStudio)'!='true'">
|
||||
<Compile Include="**\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Internal.AspNetCore.Sdk" Version="1.0.0-alpha-15156" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -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<string> ViewsToCompile => ViewsToCompileOption.Values;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,15 +38,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
|||
Host = serviceProvider.GetRequiredService<IMvcRazorHost>();
|
||||
Compiler = serviceProvider.GetRequiredService<CSharpCompiler>();
|
||||
ViewEngineOptions = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>().Value;
|
||||
FileProvider = serviceProvider.GetRequiredService<IRazorViewEngineFileProviderAccessor>().FileProvider;
|
||||
}
|
||||
|
||||
public IMvcRazorHost Host { get; }
|
||||
|
||||
public CSharpCompiler Compiler { get; }
|
||||
|
||||
public IFileProvider FileProvider { get; }
|
||||
|
||||
public RazorViewEngineOptions ViewEngineOptions { get; }
|
||||
|
||||
private IDesignTimeMvcBuilderConfiguration GetConfigureCompilationAction(string configureCompilationType)
|
||||
|
|
|
@ -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<RelativeFileInfo>();
|
||||
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<RelativeFileInfo> razorFiles, string root)
|
||||
private List<ViewFileInfo> GetRazorFiles()
|
||||
{
|
||||
foreach (var fileInfo in fileProvider.GetDirectoryContents(root))
|
||||
var contentRoot = Options.ContentRootOption.Value();
|
||||
var viewFiles = Options.ViewsToCompile;
|
||||
var relativeFiles = new List<ViewFileInfo>(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)
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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})),");
|
||||
}
|
||||
|
|
|
@ -13,10 +13,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
<None Include="build\**\*" Pack="true" PackagePath="%(Identity)" />
|
||||
<None Include="buildMultiTargeting/*" Pack="true" PackagePath="%(Identity)" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))</_MvcRazorOutputPath>
|
||||
<_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath)</_MvcRazorOutputPath>
|
||||
<_MvcRazorOutputFullPath>$([System.IO.Path]::Combine($(_MvcRazorOutputPath), '$(MSBuildProjectName).PrecompiledViews.dll'))</_MvcRazorOutputFullPath>
|
||||
<_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp</_MvcRazorResponseFilePath>
|
||||
<Target Name="_ResolveInputArguments">
|
||||
<PropertyGroup>
|
||||
<_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))</_MvcRazorOutputPath>
|
||||
<_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath)</_MvcRazorOutputPath>
|
||||
<_MvcRazorOutputFullPath>$(_MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.dll</_MvcRazorOutputFullPath>
|
||||
<_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp</_MvcRazorResponseFilePath>
|
||||
|
||||
<MvcRazorContentRoot Condition="'$(MvcRazorContentRoot)'==''">$(MSBuildProjectDirectory)</MvcRazorContentRoot>
|
||||
<MvcRazorExcludeViewFilesFromPublish Condition="'$(MvcRazorExcludeViewFilesFromPublish)'==''">true</MvcRazorExcludeViewFilesFromPublish>
|
||||
</PropertyGroup>
|
||||
<MvcRazorContentRoot Condition="'$(MvcRazorContentRoot)'==''">$(MSBuildProjectDirectory)</MvcRazorContentRoot>
|
||||
<MvcRazorExcludeViewFilesFromPublish Condition="'$(MvcRazorExcludeViewFilesFromPublish)'==''">true</MvcRazorExcludeViewFilesFromPublish>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_MvcRazorContentFiles Include="$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))**\*.cshtml" />
|
||||
<Content
|
||||
Update="**\*.cshtml"
|
||||
CopyToPublishDirectory="Never"
|
||||
Condition="'$(MvcRazorCompileOnPublish)'=='true' AND '$(MvcRazorExcludeViewFilesFromPublish)'=='true'" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'@(MvcRazorFilesToCompile)' == ''">
|
||||
<MvcRazorFilesToCompile Include="@(Content)" Condition="'%(Extension)'=='.cshtml'" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="_CreateResponseFileForMvcRazorPrecompile">
|
||||
<ItemGroup>
|
||||
|
@ -28,6 +26,8 @@
|
|||
<ExecArgs
|
||||
Condition="'$(MvcRazorEmbedViewSources)'=='true'"
|
||||
Include="--embed-view-sources" />
|
||||
|
||||
<ExecArgs Include="--file=%(MvcRazorFilesToCompile.FullPath)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(SignAssembly)'=='true'">
|
||||
|
@ -46,13 +46,21 @@
|
|||
Overwrite="true" />
|
||||
</Target>
|
||||
|
||||
<Target
|
||||
Name="_MvcRazorPrecompileOnPublish"
|
||||
DependsOnTargets="MvcRazorPrecompile"
|
||||
AfterTargets="PrepareForPublish"
|
||||
Condition="'$(MvcRazorCompileOnPublish)'=='true'">
|
||||
<Target
|
||||
Name="_MvcRazorPrecompileOnPublish"
|
||||
DependsOnTargets="MvcRazorPrecompile"
|
||||
AfterTargets="PrepareForPublish"
|
||||
Condition="'$(MvcRazorCompileOnPublish)'=='true'" />
|
||||
|
||||
<Target Name="_MvcRazorResolveFilesToCompute"
|
||||
AfterTargets="ComputeFilesToPublish"
|
||||
Condition="'$(MvcRazorCompileOnPublish)'=='true'">
|
||||
|
||||
<ItemGroup>
|
||||
<ResolvedFileToPublish
|
||||
Remove="%(MvcRazorFilesToCompile.FullPath)"
|
||||
Condition="'$(MvcRazorExcludeViewFilesFromPublish)'=='true'" />
|
||||
|
||||
<ResolvedFileToPublish Include="$(_MvcRazorOutputFullPath)" CopyToPublishDirectory="Always">
|
||||
<RelativePath>$([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)'))</RelativePath>
|
||||
</ResolvedFileToPublish>
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
<Target
|
||||
Name="MvcRazorPrecompile"
|
||||
Inputs="$(MSBuildThisFileFullPath);@(_MvcRazorContentFiles);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects);"
|
||||
DependsOnTargets="_ResolveInputArguments"
|
||||
Inputs="$(MSBuildThisFileFullPath);@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects);"
|
||||
Outputs="$(_MvcRazorOutputFullPath)">
|
||||
|
||||
<CallTarget Targets="_CreateResponseFileForMvcRazorPrecompile" />
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
</PropertyGroup>
|
||||
<Target
|
||||
Name="MvcRazorPrecompile"
|
||||
Inputs="$(MSBuildThisFileFullPath);@(_MvcRazorContentFiles);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects)"
|
||||
DependsOnTargets="_ResolveInputArguments"
|
||||
Inputs="$(MSBuildThisFileFullPath);@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects)"
|
||||
Outputs="$(_MvcRazorOutputFullPath)">
|
||||
|
||||
<CallTarget Targets="_CreateResponseFileForMvcRazorPrecompile" />
|
||||
|
|
|
@ -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<ApplicationWithCustomInputFilesTest.ApplicationWithCustomInputFilesTestFixture>
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
<EmbeddedResource Include="Resources\*" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
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
|
||||
|
||||
<h1>Admin home page</h1>
|
||||
|
||||
|
|
|
@ -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
|
||||
<br />Hello world!
|
|
@ -8,7 +8,7 @@
|
|||
<body>
|
||||
<div class="container body-content">
|
||||
|
||||
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
|
||||
<div><b>To boldy tag that no one has ever tagged before...</b></div>
|
||||
|
||||
|
||||
|
@ -20,6 +20,6 @@ AspNetCore.Views_Home_ClassLibraryTagHelper_cshtml, ApplicationWithTagHelpers.Pr
|
|||
</footer>
|
||||
</div>
|
||||
|
||||
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
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<body>
|
||||
<div class="container body-content">
|
||||
|
||||
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
|
||||
<test href="/Home/About">TestTagHelper content.</test>
|
||||
|
||||
|
||||
|
@ -20,6 +20,6 @@ AspNetCore.Views_Home_LocalTagHelper_cshtml, ApplicationWithTagHelpers.Precompil
|
|||
</footer>
|
||||
</div>
|
||||
|
||||
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
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
</div>
|
||||
<div class="container body-content">
|
||||
|
||||
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
|
||||
<hr />
|
||||
<footer>
|
||||
<p>© 2016 - SimpleApp</p>
|
||||
|
@ -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
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
</div>
|
||||
<div class="container body-content">
|
||||
|
||||
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
|
||||
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="6000">
|
||||
<ol class="carousel-indicators">
|
||||
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
|
||||
|
@ -160,6 +160,6 @@ AspNetCore.Views_Home_Index_cshtml, SimpleApp.PrecompiledViews, Version=1.0.0.0,
|
|||
|
||||
|
||||
|
||||
AspNetCore.Views_Shared__Layout_cshtml, SimpleApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
AspNetCore._Views_Shared__Layout_cshtml, SimpleApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Hello from view in AspNetCore.Views_Home_Index_cshtml, StrongNamedApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
|
||||
Hello from view in AspNetCore._Views_Home_Index_cshtml, StrongNamedApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -25,18 +25,19 @@ $@"Microsoft Razor Precompilation Utility {GetToolVersion()}
|
|||
Usage: razor-precompile [arguments] [options]
|
||||
|
||||
Arguments:
|
||||
project The path to the project (project folder or project.json) with precompilation.
|
||||
project The path to the project file.
|
||||
|
||||
Options:
|
||||
-?|-h|--help Show help information
|
||||
--output-path Path to the emit the precompiled assembly to.
|
||||
--application-name Name of the application to produce precompiled assembly for.
|
||||
--configure-compilation-type Type with Configure method
|
||||
--content-root The application's content root.
|
||||
--embed-view-sources Embed view sources as resources in the generated assembly.
|
||||
--key-file Strong name key path
|
||||
--key-file Strong name key path.
|
||||
--delay-sign Determines if the precompiled view assembly is to be delay signed.
|
||||
--public-sign Determines if the precompiled view assembly is to be public signed.
|
||||
--output-path Path to the emit the precompiled assembly to.
|
||||
--application-name Name of the application to produce precompiled assembly for.";
|
||||
--file Razor files to compile.";
|
||||
|
||||
var args = new[]
|
||||
{
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web" ToolsVersion="15.0">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp1.1;net451</TargetFrameworks>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier Condition="!$(TargetFramework.StartsWith('netcoreapp'))">win7-x64</RuntimeIdentifier>
|
||||
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
|
||||
<MvcRazorEmbedViewSources>true</MvcRazorEmbedViewSources>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<MvcRazorFilesToCompile Include="Views/Home/Index.cshtml;Views/Home/About.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation">
|
||||
<Version>1.1.0-*</Version>
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
|
||||
<PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
||||
|
||||
namespace ApplicationWithCustomInputFiles.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public string GetPrecompiledResourceNames([FromServices] ApplicationPartManager applicationManager)
|
||||
{
|
||||
var feature = new ViewsFeature();
|
||||
applicationManager.PopulateFeature(feature);
|
||||
return string.Join(Environment.NewLine, feature.Views.Keys);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ApplicationWithCustomInputFiles
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
|
||||
.Build();
|
||||
|
||||
var host = new WebHostBuilder()
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ApplicationWithCustomInputFiles
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole();
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Hello from About
|
|
@ -0,0 +1 @@
|
|||
Hello Index!
|
|
@ -0,0 +1 @@
|
|||
This file is not included in compilation.
|
Загрузка…
Ссылка в новой задаче