Make PreserveCompilationContext=true
This commit is contained in:
parent
da255ff9db
commit
1e11b5fa95
|
|
@ -62,6 +62,8 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
Configures the file extension used for generated C# files.
|
||||
-->
|
||||
<RazorGenerateOutputFileExtension>.g.cshtml.cs</RazorGenerateOutputFileExtension>
|
||||
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(EnableDefaultItems)' == 'true' And '$(EnableDefaultContentItems)' == 'true'">
|
||||
|
|
|
|||
|
|
@ -69,11 +69,6 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
_RazorAddDebugSymbolsProjectOutputGroupOutput
|
||||
</DebugSymbolsProjectOutputGroupDependsOn>
|
||||
|
||||
<PrepareForBuildDependsOn>
|
||||
_InitializePreserveCompilationContext;
|
||||
$(PrepareForBuildDependsOn)
|
||||
</PrepareForBuildDependsOn>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
|
|
@ -172,13 +167,6 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<MvcRazorCompileOnPublish Condition="'$(MvcRazorCompileOnPublish)' == ''">true</MvcRazorCompileOnPublish>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Set PreserveCompilationContext = true, if RazorCompileToolSet = PrecompilationTool since the precompilation tool requires it to work correctly.
|
||||
This is an important to maintain back-compat when the Sdk is used to compile 2.0 applications.
|
||||
-->
|
||||
<PreserveCompilationContext Condition="'$(PreserveCompilationContext)'=='' AND '$(ResolvedRazorCompileToolset)' == 'PrecompilationTool'">true</PreserveCompilationContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
Properties that configure Razor SDK, but need to be defined in targets due to evaluation order.
|
||||
-->
|
||||
|
|
@ -219,16 +207,6 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<Target Name="RazorCompile" DependsOnTargets="$(RazorCompileDependsOn)">
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
PreserveCompilationContext needs to enabled by default only for "applications" (OutputType = exe) which have one or more Razor files.
|
||||
We cannot only inspect ItemGroups globally, therefore setting this must be done inside a target. We wire this up to run before Build.
|
||||
-->
|
||||
<Target Name="_InitializePreserveCompilationContext">
|
||||
<PropertyGroup Condition="'$(PreserveCompilationContext)' == '' AND '$(OutputType)' == 'exe' AND '@(Content->AnyHaveMetadataValue('Extension', '.cshtml'))' == 'true'">
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
</PropertyGroup>
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
Computes the applicable @(ResolvedRazorConfiguration) and @(ResolvedRazorExtension) items that match the project's
|
||||
configuration.
|
||||
|
|
|
|||
|
|
@ -255,61 +255,6 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.Contains(customDefine, dependencyContext.CompilationOptions.Defines);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_WithoutViews_ProducesDepsFileWithoutCompiilationContext()
|
||||
{
|
||||
Directory.Delete(Path.Combine(Project.DirectoryPath, "Views"), recursive: true);
|
||||
var customDefine = "RazorSdkTest";
|
||||
var result = await DotnetMSBuild("Build", $"/p:DefineConstants={customDefine}");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.deps.json");
|
||||
var depsFilePath = Path.Combine(Project.DirectoryPath, OutputPath, "SimpleMvc.deps.json");
|
||||
var dependencyContext = ReadDependencyContext(depsFilePath);
|
||||
Assert.All(dependencyContext.CompileLibraries, library => Assert.Empty(library.Assemblies));
|
||||
Assert.Empty(dependencyContext.CompilationOptions.Defines);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_WithoutViews_ProducesDepsFileWithCompiilationContext_WhenUsingPrecompilationTool()
|
||||
{
|
||||
Directory.Delete(Path.Combine(Project.DirectoryPath, "Views"), recursive: true);
|
||||
var customDefine = "RazorSdkTest";
|
||||
var result = await DotnetMSBuild("Build", $"/p:DefineConstants={customDefine} /p:MvcRazorCompileOnPublish=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.deps.json");
|
||||
var depsFilePath = Path.Combine(Project.DirectoryPath, OutputPath, "SimpleMvc.deps.json");
|
||||
var dependencyContext = ReadDependencyContext(depsFilePath);
|
||||
|
||||
// Pick a couple of libraries and ensure they have some compile references
|
||||
var packageReference = dependencyContext.CompileLibraries.First(l => l.Name == "Microsoft.AspNetCore.Html.Abstractions");
|
||||
Assert.NotEmpty(packageReference.Assemblies);
|
||||
|
||||
var projectReference = dependencyContext.CompileLibraries.First(l => l.Name == "SimpleMvc");
|
||||
Assert.NotEmpty(packageReference.Assemblies);
|
||||
|
||||
Assert.Contains(customDefine, dependencyContext.CompilationOptions.Defines);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("ClassLibrary")]
|
||||
public async Task Build_ClassLibrary_ProducesDepsFileWithoutCompiilationContext()
|
||||
{
|
||||
var result = await DotnetMSBuild("Build");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
Assert.FileExists(result, OutputPath, "ClassLibrary.deps.json");
|
||||
var depsFilePath = Path.Combine(Project.DirectoryPath, OutputPath, "ClassLibrary.deps.json");
|
||||
var dependencyContext = ReadDependencyContext(depsFilePath);
|
||||
Assert.All(dependencyContext.CompileLibraries, library => Assert.Empty(library.Assemblies));
|
||||
Assert.Empty(dependencyContext.CompilationOptions.Defines);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("ClassLibrary")]
|
||||
public async Task Build_CodeGensAssemblyInfoUsingValuesFromProject()
|
||||
|
|
|
|||
Loading…
Reference in New Issue