Update View Compilation for new Razor
This commit is contained in:
Родитель
32cd737b62
Коммит
9dbc119ed1
|
@ -9,10 +9,12 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Hosting.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
||||
using Microsoft.AspNetCore.Razor.Evolution;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||
{
|
||||
|
@ -35,12 +37,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
|||
var mvcBuilderConfiguration = GetConfigureCompilationAction(configureCompilationType);
|
||||
var serviceProvider = GetProvider(mvcBuilderConfiguration);
|
||||
|
||||
Host = serviceProvider.GetRequiredService<IMvcRazorHost>();
|
||||
CompilationService = (RazorCompilationService)serviceProvider.GetRequiredService<IRazorCompilationService>();
|
||||
Engine = serviceProvider.GetRequiredService<RazorEngine>();
|
||||
Compiler = serviceProvider.GetRequiredService<CSharpCompiler>();
|
||||
ViewEngineOptions = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>().Value;
|
||||
}
|
||||
|
||||
public IMvcRazorHost Host { get; }
|
||||
|
||||
public RazorCompilationService CompilationService { get; }
|
||||
|
||||
public RazorEngine Engine { get; }
|
||||
|
||||
public CSharpCompiler Compiler { get; }
|
||||
|
||||
|
|
|
@ -59,10 +59,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
|||
var success = true;
|
||||
foreach (var result in results)
|
||||
{
|
||||
if (!result.GeneratorResults.Success)
|
||||
if (result.CSharpDocument.Diagnostics.Count > 0)
|
||||
{
|
||||
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}");
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
|||
Parallel.For(0, results.Length, ParalellOptions, 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 syntaxTree = compiler.CreateSyntaxTree(sourceText)
|
||||
.WithFilePath(fileInfo.FullPath ?? fileInfo.ViewEnginePath);
|
||||
|
@ -237,7 +237,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
|||
var fileInfo = files[i];
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,7 +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 Microsoft.AspNetCore.Razor.CodeGenerators;
|
||||
using Microsoft.AspNetCore.Razor.Evolution;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||
{
|
||||
|
@ -9,15 +9,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
|||
{
|
||||
public ViewCompilationInfo(
|
||||
ViewFileInfo viewFileInfo,
|
||||
GeneratorResults generatorResults)
|
||||
RazorCSharpDocument cSharpDocument)
|
||||
{
|
||||
ViewFileInfo = viewFileInfo;
|
||||
GeneratorResults = generatorResults;
|
||||
CSharpDocument = cSharpDocument;
|
||||
}
|
||||
|
||||
public ViewFileInfo ViewFileInfo { get; }
|
||||
|
||||
public GeneratorResults GeneratorResults { get; }
|
||||
public RazorCSharpDocument CSharpDocument { get; }
|
||||
|
||||
public string TypeName { get; set; }
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[ConditionalTheory]
|
||||
[ConditionalTheory(Skip = "MVC #5736")]
|
||||
[OSSkipCondition(OperatingSystems.Linux,
|
||||
SkipReason = "https://github.com/NuGet/Home/issues/4243, https://github.com/NuGet/Home/issues/4240")]
|
||||
[OSSkipCondition(OperatingSystems.MacOSX,
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[Theory]
|
||||
[Theory(Skip = "MVC #5736")]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
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))]
|
||||
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor)
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[Theory]
|
||||
[Theory(Skip = "MVC #5736")]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
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))]
|
||||
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))]
|
||||
public async Task Precompilation_WorksForViewsThatUseTagHelpers(string url, RuntimeFlavor flavor)
|
||||
{
|
||||
|
|
|
@ -4,11 +4,9 @@
|
|||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
<DefineConstants>$(DefineConstants);__remove_this_to__GENERATE_BASELINES</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.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="xunit" Version="2.2.0-*" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests
|
|||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[Theory]
|
||||
[Theory(Skip = "MVC #5736")]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
public async Task Precompilation_CanEmbedViewSourcesAsResources(RuntimeFlavor flavor)
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
|
||||
public ApplicationTestFixture Fixture { get; }
|
||||
|
||||
[ConditionalFact]
|
||||
[ConditionalFact(Skip = "MVC #5736")]
|
||||
[OSSkipConditionAttribute(OperatingSystems.Linux)]
|
||||
[OSSkipConditionAttribute(OperatingSystems.MacOSX)]
|
||||
public async Task Precompilation_WorksForSimpleApps()
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[Theory]
|
||||
[Theory(Skip = "MVC #5736")]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[Theory]
|
||||
[Theory(Skip = "MVC #5736")]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication(RuntimeFlavor flavor)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче