Implment support for publish
This commit is contained in:
parent
07a63d2ddd
commit
f0c3843a5b
|
|
@ -1,12 +1,19 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<!-- Similar to https://github.com/Microsoft/msbuild/blob/908cc9ccd4961441628f68e37a148183a87bb067/src/Tasks/Microsoft.Common.CurrentVersion.targets#L146-L153 -->
|
||||
<_RazorDebugSymbolsProduced>false</_RazorDebugSymbolsProduced>
|
||||
<_RazorDebugSymbolsProduced Condition="'$(DebugSymbols)'=='true'">true</_RazorDebugSymbolsProduced>
|
||||
<_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='none'">false</_RazorDebugSymbolsProduced>
|
||||
<_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='pdbonly'">true</_RazorDebugSymbolsProduced>
|
||||
<_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='full'">true</_RazorDebugSymbolsProduced>
|
||||
<_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='portable'">true</_RazorDebugSymbolsProduced>
|
||||
<_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='embedded'">false</_RazorDebugSymbolsProduced>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Used to creating the final compiled Razor dll -->
|
||||
<RazorIntermediateAssembly Include="$(IntermediateOutputPath)$(RazorTargetName).dll" />
|
||||
|
||||
<!-- Similar to https://github.com/Microsoft/msbuild/blob/908cc9ccd4961441628f68e37a148183a87bb067/src/Tasks/Microsoft.Common.CurrentVersion.targets#L146-L153 -->
|
||||
<_RazorDebugSymbolsIntermediatePath
|
||||
Condition="'$(DebugSymbols)'=='true' and '$(DebugType)'!='' and '$(DebugType)'!='none' and '$(DebugType)'!='embedded'"
|
||||
Include="$(IntermediateOutputPath)$(RazorTargetName).pdb" />
|
||||
<_RazorDebugSymbolsIntermediatePath Condition="'$(_RazorDebugSymbolsProduced)'=='true'" Include="$(IntermediateOutputPath)$(RazorTargetName).pdb" />
|
||||
<_RazorDebugSymbolsOutputPath Include="@(_RazorDebugSymbolsIntermediatePath->'$(OutDir)%(Filename)%(Extension)')" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
-->
|
||||
<PropertyGroup>
|
||||
<RazorCompileOnBuild Condition="'$(RazorCompileOnBuild)'==''">false</RazorCompileOnBuild>
|
||||
<RazorCompileOnPublish Condition="'$(RazorCompileOnPublish)'==''">false</RazorCompileOnPublish>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@
|
|||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
This target will only be called when we have some .cshtml files that are going to participate in code generation.
|
||||
|
||||
This is part of the chain of targets that are called once we've actually committed to generating code.
|
||||
-->
|
||||
<Target
|
||||
Name="_ResolveRazorCoreGenerateInputs"
|
||||
DependsOnTargets="RazorResolveGenerateInputs"
|
||||
|
|
@ -156,6 +161,20 @@
|
|||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
This target is called after PrepareForPublish when RazorCompileOnBuild=true so that we can hook into publish.
|
||||
This target just hooks up other targets since Publish and PrepareForPublish don't have a DependsOnTargets
|
||||
property we can use.
|
||||
-->
|
||||
<Target
|
||||
Name="_RazorPrepareForPublish"
|
||||
AfterTargets="PrepareForPublish"
|
||||
DependsOnTargets="RazorCompile">
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
This target adds the Razor assembly to the BuiltProjectOutputGroupOutput - which is used as input to the Pack target.
|
||||
-->
|
||||
<Target
|
||||
Name="_RazorAddBuiltProjectOutputGroupOutput"
|
||||
DependsOnTargets="RazorResolveGenerateInputs"
|
||||
|
|
@ -167,11 +186,20 @@
|
|||
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
Called as part of GetCopyToOutputDirectoryItems - this target populates the list of items that get
|
||||
copied to the output directory when building as a project reference.
|
||||
-->
|
||||
<Target
|
||||
Name="_RazorGetCopyToOutputDirectoryItems"
|
||||
DependsOnTargets="RazorResolveGenerateInputs">
|
||||
Name="_RazorGetCopyToOutputDirectoryItems"
|
||||
DependsOnTargets="RazorCompile"
|
||||
Condition="'$(RazorCompileOnBuild)'=='true'">
|
||||
|
||||
<ItemGroup Condition="'@(RazorGenerate)'!= '' and '$(RazorCompileOnBuild)' == 'true'">
|
||||
<!--
|
||||
This condition needs to be inside the target because it the itemgroup will be populated after the target's
|
||||
condition is evaluated.
|
||||
-->
|
||||
<ItemGroup Condition="'@(RazorGenerate)'!=''">
|
||||
<AllItemsFullPathWithTargetPath Include="@(RazorIntermediateAssembly->'%(FullPath)')">
|
||||
<TargetPath>%(Filename)%(Extension)</TargetPath>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
|
@ -184,6 +212,40 @@
|
|||
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
Called as part of GetCopyToPublishDirectoryItems - this target populates the list of items that get
|
||||
copied to the publish directory when publishing as a project reference.
|
||||
|
||||
The dependency on RazorCompile is needed because this will be called during publish on each P2P
|
||||
reference without calling RazorCompile for the P2P references.
|
||||
-->
|
||||
<Target
|
||||
Name="_RazorGetCopyToPublishDirectoryItems"
|
||||
BeforeTargets="GetCopyToPublishDirectoryItems"
|
||||
DependsOnTargets="RazorCompile"
|
||||
Condition="'$(RazorCompileOnBuild)'=='true' or '$(RazorCompileOnPublish)'=='true'">
|
||||
|
||||
<!--
|
||||
This condition needs to be inside the target because it the itemgroup will be populated after the target's
|
||||
condition is evaluated.
|
||||
-->
|
||||
<ItemGroup Condition="'@(RazorGenerate)'!=''">
|
||||
<AllPublishItemsFullPathWithTargetPath Include="@(RazorIntermediateAssembly->'%(FullPath)')">
|
||||
<TargetPath>%(Filename)%(Extension)</TargetPath>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</AllPublishItemsFullPathWithTargetPath>
|
||||
<AllPublishItemsFullPathWithTargetPath Include="@(_RazorDebugSymbolsIntermediatePath->'%(FullPath)')">
|
||||
<TargetPath>%(Filename)%(Extension)</TargetPath>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</AllPublishItemsFullPathWithTargetPath>
|
||||
</ItemGroup>
|
||||
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
Called as part of CopyFilesToOutputDirectory - this target is called when building the project to copy
|
||||
files to the output directory.
|
||||
-->
|
||||
<Target Name="_RazorCopyFilesToOutputDirectory">
|
||||
|
||||
<!-- Copy the Razor dll -->
|
||||
|
|
@ -224,4 +286,23 @@
|
|||
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
Called after ComputeFilesToPublish - this target is called when publishing the project to get a list of
|
||||
files to the output directory.
|
||||
-->
|
||||
<Target
|
||||
Name="_RazorComputeFilesToPublish"
|
||||
AfterTargets="ComputeFilesToPublish">
|
||||
|
||||
<ItemGroup Condition="'@(RazorGenerate)'!='' and ('$(RazorCompileOnBuild)'=='true' or '$(RazorCompileOnPublish)'=='true')">
|
||||
<ResolvedFileToPublish Include="@(RazorIntermediateAssembly)" Condition="'$(CopyBuildOutputToPublishDirectory)'=='true'">
|
||||
<RelativePath>@(RazorIntermediateAssembly->'%(Filename)%(Extension)')</RelativePath>
|
||||
</ResolvedFileToPublish>
|
||||
<ResolvedFileToPublish Include="@(_RazorDebugSymbolsIntermediatePath)" Condition="'$(CopyOutputSymbolsToPublishDirectory)'=='true'">
|
||||
<RelativePath>@(_RazorDebugSymbolsIntermediatePath->'%(Filename)%(Extension)')</RelativePath>
|
||||
</ResolvedFileToPublish>
|
||||
</ItemGroup>
|
||||
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -56,6 +56,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_SimpleMvc_NoopsWithRazorCompileOnPublish()
|
||||
{
|
||||
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnPublish=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_ErrorInGeneratedCode_ReportsMSBuildError()
|
||||
|
|
@ -139,10 +152,15 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, OutputPath, "AppWithP2PReference.dll");
|
||||
Assert.FileExists(result, OutputPath, "AppWithP2PReference.pdb");
|
||||
Assert.FileExists(result, OutputPath, "AppWithP2PReference.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, OutputPath, "AppWithP2PReference.PrecompiledViews.pdb");
|
||||
Assert.FileExists(result, OutputPath, "ClassLibrary.dll");
|
||||
Assert.FileExists(result, OutputPath, "ClassLibrary.pdb");
|
||||
Assert.FileExists(result, OutputPath, "ClassLibrary.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, OutputPath, "ClassLibrary.PrecompiledViews.pdb");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
|
||||
protected string OutputPath => Path.Combine("bin", Configuration, TargetFramework);
|
||||
|
||||
protected string PublishOutputPath => Path.Combine(OutputPath, "publish");
|
||||
|
||||
// Used by the test framework to set the project that we're working with
|
||||
internal static ProjectDirectory Project
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,151 @@
|
|||
// 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 System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||
{
|
||||
public class PublishIntegrationTest : MSBuildIntegrationTestBase
|
||||
{
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_WithRazorCompileOnBuild_PublishesAssembly()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnBuild=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_WithRazorCompileOnPublish_PublishesAssembly()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnPublish=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_NoopsWithNoFiles()
|
||||
{
|
||||
Directory.Delete(Path.Combine(Project.DirectoryPath, "Views"), recursive: true);
|
||||
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnBuild=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
// Everything we do should noop - including building the app.
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_SkipsCopyingBinariesToOutputDirectory_IfCopyBuildOutputToOutputDirectory_IsUnset()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnBuild=true /p:CopyBuildOutputToPublishDirectory=false");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_SkipsCopyingBinariesToOutputDirectory_IfCopyOutputSymbolsToOutputDirectory_IsUnset()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnBuild=true /p:CopyOutputSymbolsToPublishDirectory=false");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Publish_Works_WhenSymbolsAreNotGenerated()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnBuild=true /p:DebugType=none");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("AppWithP2PReference", "ClassLibrary")]
|
||||
public async Task Publish_WithP2P_AndRazorCompileOnBuild_CopiesRazorAssembly()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnBuild=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.PrecompiledViews.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("AppWithP2PReference", "ClassLibrary")]
|
||||
public async Task Publish_WithP2P_AndRazorCompileOnPublish_CopiesRazorAssembly()
|
||||
{
|
||||
var result = await DotnetMSBuild("Publish", "/p:RazorCompileOnPublish=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileDoesNotExist(result, OutputPath, "AppWithP2PReference.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "AppWithP2PReference.PrecompiledViews.pdb");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.PrecompiledViews.pdb");
|
||||
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "AppWithP2PReference.PrecompiledViews.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.pdb");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.PrecompiledViews.dll");
|
||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.PrecompiledViews.pdb");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue