Update View Compilation for new Razor
This commit is contained in:
parent
32cd737b62
commit
9dbc119ed1
|
|
@ -9,10 +9,12 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Hosting.Internal;
|
using Microsoft.AspNetCore.Hosting.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
||||||
|
using Microsoft.AspNetCore.Razor.Evolution;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.ObjectPool;
|
using Microsoft.Extensions.ObjectPool;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
{
|
{
|
||||||
|
|
@ -35,12 +37,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
var mvcBuilderConfiguration = GetConfigureCompilationAction(configureCompilationType);
|
var mvcBuilderConfiguration = GetConfigureCompilationAction(configureCompilationType);
|
||||||
var serviceProvider = GetProvider(mvcBuilderConfiguration);
|
var serviceProvider = GetProvider(mvcBuilderConfiguration);
|
||||||
|
|
||||||
Host = serviceProvider.GetRequiredService<IMvcRazorHost>();
|
CompilationService = (RazorCompilationService)serviceProvider.GetRequiredService<IRazorCompilationService>();
|
||||||
|
Engine = serviceProvider.GetRequiredService<RazorEngine>();
|
||||||
Compiler = serviceProvider.GetRequiredService<CSharpCompiler>();
|
Compiler = serviceProvider.GetRequiredService<CSharpCompiler>();
|
||||||
ViewEngineOptions = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>().Value;
|
ViewEngineOptions = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>().Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMvcRazorHost Host { get; }
|
|
||||||
|
public RazorCompilationService CompilationService { get; }
|
||||||
|
|
||||||
|
public RazorEngine Engine { get; }
|
||||||
|
|
||||||
public CSharpCompiler Compiler { get; }
|
public CSharpCompiler Compiler { get; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
var success = true;
|
var success = true;
|
||||||
foreach (var result in results)
|
foreach (var result in results)
|
||||||
{
|
{
|
||||||
if (!result.GeneratorResults.Success)
|
if (result.CSharpDocument.Diagnostics.Count > 0)
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
foreach (var error in result.GeneratorResults.ParserErrors)
|
foreach (var error in result.CSharpDocument.Diagnostics)
|
||||||
{
|
{
|
||||||
Application.Error.WriteLine($"{error.Location.FilePath} ({error.Location.LineIndex}): {error.Message}");
|
Application.Error.WriteLine($"{error.Location.FilePath} ({error.Location.LineIndex}): {error.Message}");
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
Parallel.For(0, results.Length, ParalellOptions, i =>
|
Parallel.For(0, results.Length, ParalellOptions, i =>
|
||||||
{
|
{
|
||||||
var result = results[i];
|
var result = results[i];
|
||||||
var sourceText = SourceText.From(result.GeneratorResults.GeneratedCode, Encoding.UTF8);
|
var sourceText = SourceText.From(result.CSharpDocument.GeneratedCode, Encoding.UTF8);
|
||||||
var fileInfo = result.ViewFileInfo;
|
var fileInfo = result.ViewFileInfo;
|
||||||
var syntaxTree = compiler.CreateSyntaxTree(sourceText)
|
var syntaxTree = compiler.CreateSyntaxTree(sourceText)
|
||||||
.WithFilePath(fileInfo.FullPath ?? fileInfo.ViewEnginePath);
|
.WithFilePath(fileInfo.FullPath ?? fileInfo.ViewEnginePath);
|
||||||
|
|
@ -237,7 +237,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
var fileInfo = files[i];
|
var fileInfo = files[i];
|
||||||
using (var fileStream = fileInfo.CreateReadStream())
|
using (var fileStream = fileInfo.CreateReadStream())
|
||||||
{
|
{
|
||||||
var result = MvcServiceProvider.Host.GenerateCode(fileInfo.ViewEnginePath, fileStream);
|
var codeDocument = MvcServiceProvider.CompilationService.CreateCodeDocument(fileInfo.ViewEnginePath, fileStream);
|
||||||
|
var result = MvcServiceProvider.CompilationService.ProcessCodeDocument(codeDocument);
|
||||||
results[i] = new ViewCompilationInfo(fileInfo, result);
|
results[i] = new ViewCompilationInfo(fileInfo, result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Razor.CodeGenerators;
|
using Microsoft.AspNetCore.Razor.Evolution;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
{
|
{
|
||||||
|
|
@ -9,15 +9,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
{
|
{
|
||||||
public ViewCompilationInfo(
|
public ViewCompilationInfo(
|
||||||
ViewFileInfo viewFileInfo,
|
ViewFileInfo viewFileInfo,
|
||||||
GeneratorResults generatorResults)
|
RazorCSharpDocument cSharpDocument)
|
||||||
{
|
{
|
||||||
ViewFileInfo = viewFileInfo;
|
ViewFileInfo = viewFileInfo;
|
||||||
GeneratorResults = generatorResults;
|
CSharpDocument = cSharpDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViewFileInfo ViewFileInfo { get; }
|
public ViewFileInfo ViewFileInfo { get; }
|
||||||
|
|
||||||
public GeneratorResults GeneratorResults { get; }
|
public RazorCSharpDocument CSharpDocument { get; }
|
||||||
|
|
||||||
public string TypeName { get; set; }
|
public string TypeName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
|
|
||||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory(Skip = "MVC #5736")]
|
||||||
[OSSkipCondition(OperatingSystems.Linux,
|
[OSSkipCondition(OperatingSystems.Linux,
|
||||||
SkipReason = "https://github.com/NuGet/Home/issues/4243, https://github.com/NuGet/Home/issues/4240")]
|
SkipReason = "https://github.com/NuGet/Home/issues/4243, https://github.com/NuGet/Home/issues/4240")]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX,
|
[OSSkipCondition(OperatingSystems.MacOSX,
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
|
|
||||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task Precompilation_WorksForViewsUsingRelativePath(RuntimeFlavor flavor)
|
public async Task Precompilation_WorksForViewsUsingRelativePath(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor)
|
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
|
|
||||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
|
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
|
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(ApplicationWithTagHelpersData))]
|
[MemberData(nameof(ApplicationWithTagHelpersData))]
|
||||||
public async Task Precompilation_WorksForViewsThatUseTagHelpers(string url, RuntimeFlavor flavor)
|
public async Task Precompilation_WorksForViewsThatUseTagHelpers(string url, RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,9 @@
|
||||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||||
<DefineConstants>$(DefineConstants);__remove_this_to__GENERATE_BASELINES</DefineConstants>
|
<DefineConstants>$(DefineConstants);__remove_this_to__GENERATE_BASELINES</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Resources\*" />
|
<EmbeddedResource Include="Resources\*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-*" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-*" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
|
||||||
|
|
@ -19,4 +17,7 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.2.0-*" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.2.0-*" />
|
||||||
<PackageReference Include="xunit" Version="2.2.0-*" />
|
<PackageReference Include="xunit" Version="2.2.0-*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests
|
||||||
|
|
||||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task Precompilation_CanEmbedViewSourcesAsResources(RuntimeFlavor flavor)
|
public async Task Precompilation_CanEmbedViewSourcesAsResources(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
|
|
||||||
public ApplicationTestFixture Fixture { get; }
|
public ApplicationTestFixture Fixture { get; }
|
||||||
|
|
||||||
[ConditionalFact]
|
[ConditionalFact(Skip = "MVC #5736")]
|
||||||
[OSSkipConditionAttribute(OperatingSystems.Linux)]
|
[OSSkipConditionAttribute(OperatingSystems.Linux)]
|
||||||
[OSSkipConditionAttribute(OperatingSystems.MacOSX)]
|
[OSSkipConditionAttribute(OperatingSystems.MacOSX)]
|
||||||
public async Task Precompilation_WorksForSimpleApps()
|
public async Task Precompilation_WorksForSimpleApps()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
|
|
||||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
|
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||||
|
|
||||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||||
|
|
||||||
[Theory]
|
[Theory(Skip = "MVC #5736")]
|
||||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication(RuntimeFlavor flavor)
|
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue