From f0c3843a5b2cefa791eace25d1aec7b6783eefa9 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 11 Jan 2018 20:48:16 -0800 Subject: [PATCH] Implment support for publish --- ...spNetCore.Razor.Design.Compilation.targets | 17 +- .../Microsoft.AspNetCore.Razor.Design.props | 1 + .../Microsoft.AspNetCore.Razor.Design.targets | 87 +++++++++- .../IntegrationTests/BuildIntegrationTest.cs | 18 +++ .../MSBuildIntegrationTestBase.cs | 2 + .../PublishIntegrationTest.cs | 151 ++++++++++++++++++ 6 files changed, 268 insertions(+), 8 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs diff --git a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.Compilation.targets b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.Compilation.targets index 4ef0b5cf5c..8b3921a0ac 100644 --- a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.Compilation.targets +++ b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.Compilation.targets @@ -1,12 +1,19 @@ + + + <_RazorDebugSymbolsProduced>false + <_RazorDebugSymbolsProduced Condition="'$(DebugSymbols)'=='true'">true + <_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='none'">false + <_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='pdbonly'">true + <_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='full'">true + <_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='portable'">true + <_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='embedded'">false + + - - - <_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)')" /> diff --git a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.props b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.props index 5917399133..356f23a466 100644 --- a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.props +++ b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.props @@ -21,6 +21,7 @@ --> false + false diff --git a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets index a0c47f9416..050ffe9f1d 100644 --- a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets +++ b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets @@ -50,6 +50,11 @@ + + + + + + + + Name="_RazorGetCopyToOutputDirectoryItems" + DependsOnTargets="RazorCompile" + Condition="'$(RazorCompileOnBuild)'=='true'"> - + + %(Filename)%(Extension) PreserveNewest @@ -184,6 +212,40 @@ + + + + + + + %(Filename)%(Extension) + PreserveNewest + + + %(Filename)%(Extension) + PreserveNewest + + + + + + @@ -224,4 +286,23 @@ + + + + + + @(RazorIntermediateAssembly->'%(Filename)%(Extension)') + + + @(_RazorDebugSymbolsIntermediatePath->'%(Filename)%(Extension)') + + + + + diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs index a24fa62e70..54ddc49afb 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs @@ -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"); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs index cbc17d1bbc..1bc76c5745 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs @@ -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 { diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs new file mode 100644 index 0000000000..b392445142 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs @@ -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"); + } + } +}