Ensure PreserveCompilationContext is set if we're targeting precompilation tool
PreserveCompilationContext must be set for precompilation tool to work, even when the app has no views. Fixes #2168
This commit is contained in:
parent
5f69a01cc5
commit
b74582e101
|
|
@ -166,6 +166,13 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
<MvcRazorCompileOnPublish Condition="'$(MvcRazorCompileOnPublish)' == ''">true</MvcRazorCompileOnPublish>
|
<MvcRazorCompileOnPublish Condition="'$(MvcRazorCompileOnPublish)' == ''">true</MvcRazorCompileOnPublish>
|
||||||
</PropertyGroup>
|
</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.
|
Properties that configure Razor SDK, but need to be defined in targets due to evaluation order.
|
||||||
-->
|
-->
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[InitializeTestProject("SimpleMvc")]
|
[InitializeTestProject("SimpleMvc")]
|
||||||
public async Task Build_WithoutViews_ProducesDepsFileWithotCompiilationContext()
|
public async Task Build_WithoutViews_ProducesDepsFileWithoutCompiilationContext()
|
||||||
{
|
{
|
||||||
Directory.Delete(Path.Combine(Project.DirectoryPath, "Views"), recursive: true);
|
Directory.Delete(Path.Combine(Project.DirectoryPath, "Views"), recursive: true);
|
||||||
var customDefine = "RazorSdkTest";
|
var customDefine = "RazorSdkTest";
|
||||||
|
|
@ -272,9 +272,33 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
Assert.Empty(dependencyContext.CompilationOptions.Defines);
|
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]
|
[Fact]
|
||||||
[InitializeTestProject("ClassLibrary")]
|
[InitializeTestProject("ClassLibrary")]
|
||||||
public async Task Build_ClassLibrary_DoesNotProduceDepsFileWithCompilationContext()
|
public async Task Build_ClassLibrary_ProducesDepsFileWithoutCompiilationContext()
|
||||||
{
|
{
|
||||||
var result = await DotnetMSBuild("Build");
|
var result = await DotnetMSBuild("Build");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue