Limit PreserveCompilationReferences to netcoreapp (<2.x)and net4x projects
\n\nCommit migrated from b9c695c2d5
This commit is contained in:
parent
8dcf4b37f5
commit
4eb4cef18c
|
|
@ -42,14 +42,6 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
-->
|
||||
<CopyRazorGenerateFilesToPublishDirectory Condition="'$(CopyRazorGenerateFilesToPublishDirectory)'==''">false</CopyRazorGenerateFilesToPublishDirectory>
|
||||
|
||||
<!--
|
||||
Set to true to copy reference assembly items to the publish directory.
|
||||
|
||||
Typically reference assemblies are not needed for a published application if Razor compilation occurs at build-time
|
||||
or publish-time. By default, the Razor SDK will suppress the copying of reference assemblies to the publish directory.
|
||||
-->
|
||||
<CopyRefAssembliesToPublishDirectory Condition="'$(CopyRefAssembliesToPublishDirectory)'==''">false</CopyRefAssembliesToPublishDirectory>
|
||||
|
||||
<!--
|
||||
Determines the toolset to use to compile Razor (.cshtml) files. Defaults to 'Implicit' to let the Razor Sdk determine the toolset to use.
|
||||
Valid values include 'Implicit', 'RazorSdk', and 'PrecompilationTool'.
|
||||
|
|
|
|||
|
|
@ -217,6 +217,12 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<CopyRefAssembliesToPublishDirectory Condition="'$(MvcRazorExcludeRefAssembliesFromPublish)'=='true'">false</CopyRefAssembliesToPublishDirectory>
|
||||
<CopyRefAssembliesToPublishDirectory Condition="'$(MvcRazorExcludeRefAssembliesFromPublish)'=='false'">true</CopyRefAssembliesToPublishDirectory>
|
||||
|
||||
<!-- Use PreserveCompilationReferences to determine the behavior of CopyRefAssembliesToPublishDirectory if not explicitly specified by the project. -->
|
||||
<CopyRefAssembliesToPublishDirectory Condition="'$(CopyRefAssembliesToPublishDirectory)'==''">$(PreserveCompilationReferences)</CopyRefAssembliesToPublishDirectory>
|
||||
|
||||
<!-- For 2.x projects desktop and .NET Core projects, if they're opting in to runtime compilation (indicated by PreserveCompilationContext=true), set PreserveCompilationReferences = true -->
|
||||
<PreserveCompilationReferences Condition="'$(PreserveCompilationContext)' == 'true' AND (('$(TargetFrameworkIdentifier)' == '.NETFramework') OR ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' < '3.0'))">true</PreserveCompilationReferences>
|
||||
|
||||
<!--
|
||||
We can't set the actual default value here due to evaluation order (depends on $(OutDir)).
|
||||
|
||||
|
|
@ -279,9 +285,11 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<!-- Back-compat for PrecompilationTool -->
|
||||
<PropertyGroup>
|
||||
<!--
|
||||
Always enable PreserveCompilationReferences for non 3.0 projects. This preserves parity with the 2.x SDK's behavior.
|
||||
For 2.x desktop targeting projects using MvcPrecompilation, ref assemblies are required to compile the PrecompiledViews.dll,
|
||||
but are removed by the tool once done. Set PreserveCompilationReferences = true, ignoring any value configured in the project,
|
||||
if the project is using the precompilation tool.
|
||||
-->
|
||||
<PreserveCompilationReferences Condition="'$(_TargetingNETCoreApp30OrLater)' != 'true'">true</PreserveCompilationReferences>
|
||||
<PreserveCompilationReferences Condition="'$(ResolvedRazorCompileToolset)'=='PrecompilationTool'">true</PreserveCompilationReferences>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
|
|
@ -801,10 +809,10 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<Target
|
||||
Name="_RazorRemoveRefAssembliesFromPublish"
|
||||
BeforeTargets="PrepareForPublish"
|
||||
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnPublish)'=='true' AND '$(CopyRefAssembliesToPublishDirectory)'!=''">
|
||||
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnPublish)'=='true' AND '$(CopyRefAssembliesToPublishDirectory)' != ''">
|
||||
<!--
|
||||
Setting PreserveCompilationReferences affects both Build and Publish, but we want CopyRefAssembliesToPublishDirectory to only affect publishing.
|
||||
If CopyRefAssembliesToPublishDirectory is disabled, clear PreserveCompilationReferences to stop publishing ref assemblies.
|
||||
Use the value of CopyRefAssembliesToPublishDirectory to determine PreserveCompilationReferences during publish.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PreserveCompilationReferences>$(CopyRefAssembliesToPublishDirectory)</PreserveCompilationReferences>
|
||||
|
|
|
|||
|
|
@ -74,6 +74,36 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.FileDoesNotExist(result, OutputPath, "ComponentLibrary.Views.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("ComponentLibrary")]
|
||||
public async Task Build_DoesNotProduceRefsDirectory()
|
||||
{
|
||||
TargetFramework = "netstandard2.0";
|
||||
|
||||
// Build
|
||||
var result = await DotnetMSBuild("Build");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, OutputPath, "ComponentLibrary.dll");
|
||||
Assert.FileCountEquals(result, 0, Path.Combine(OutputPath, "refs"), "*.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("ComponentLibrary")]
|
||||
public async Task Publish_DoesNotProduceRefsDirectory()
|
||||
{
|
||||
TargetFramework = "netstandard2.0";
|
||||
|
||||
// Build
|
||||
var result = await DotnetMSBuild("Publish");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "ComponentLibrary.dll");
|
||||
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll");
|
||||
}
|
||||
|
||||
private async Task Build_ComponentsWorks(MSBuildProcessKind msBuildProcessKind)
|
||||
{
|
||||
var result = await DotnetMSBuild("Build", msBuildProcessKind: msBuildProcessKind);
|
||||
|
|
|
|||
|
|
@ -144,8 +144,6 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_NoopsWith_RazorCompileOnPublishFalse()
|
||||
|
|
|
|||
Loading…
Reference in New Issue