Add support for CopyBuildOutputToOutputDirectory and CopyOutputSymbolsToOutputDirectory
Fixes #1896
This commit is contained in:
parent
16324c3126
commit
bf52e0dbf0
|
|
@ -0,0 +1,167 @@
|
|||
<Project>
|
||||
<!--
|
||||
What follows here was copied and modified from the XamlPreCompile target in
|
||||
Microsoft.CSharp.CurrentVersion.targets
|
||||
|
||||
The XamlPreCompile target must remain identical to
|
||||
the CoreCompile target in Microsoft.CSharp.Core.targets.
|
||||
Any updates to one must be made to the other.
|
||||
-->
|
||||
|
||||
|
||||
<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 -->
|
||||
<_RazorIntermediatePdb
|
||||
Condition="'$(DebugSymbols)'=='true' and '$(DebugType)'!='' and '$(DebugType)'!='none' and '$(DebugType)'!='embedded'"
|
||||
Include="$(IntermediateOutputPath)$(RazorTargetName).pdb" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target
|
||||
Name="RazorCoreCompile"
|
||||
Inputs="$(MSBuildAllProjects);
|
||||
@(_RazorGenerated);
|
||||
@(_CoreCompileResourceInputs);
|
||||
$(ApplicationIcon);
|
||||
$(AssemblyOriginatorKeyFile);
|
||||
@(RazorReferencePath);"
|
||||
|
||||
Outputs="@(_RazorIntermediateAssembly);
|
||||
@(_RazorIntermediatePdb)"
|
||||
Returns=""
|
||||
DependsOnTargets="_RazorResolveTagHelpers;RazorCoreGenerate">
|
||||
|
||||
<!-- These two compiler warnings are raised when a reference is bound to a different version
|
||||
than specified in the assembly reference version number. MSBuild raises the same warning in this case,
|
||||
so the compiler warning would be redundant. -->
|
||||
<PropertyGroup Condition="('$(TargetFrameworkVersion)' != 'v1.0') and ('$(TargetFrameworkVersion)' != 'v1.1')">
|
||||
<NoWarn>$(NoWarn);1701;1702</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- To match historical behavior, when inside VS11+ disable the warning from csc.exe indicating that no sources were passed in-->
|
||||
<NoWarn Condition=" '$(BuildingInsideVisualStudio)' == 'true' and '$(VisualStudioVersion)' != '' and '$(VisualStudioVersion)' > '10.0' ">$(NoWarn);2008</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetingClr2Framework)'=='true'">
|
||||
<ReferencePath>
|
||||
<EmbedInteropTypes/>
|
||||
</ReferencePath>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- If the user has specified AppConfigForCompiler, we'll use it. If they have not, but they set UseAppConfigForCompiler,
|
||||
then we'll use AppConfig -->
|
||||
<AppConfigForCompiler Condition="'$(AppConfigForCompiler)' == '' and '$(UseAppConfigForCompiler)' == 'true'">$(AppConfig)</AppConfigForCompiler>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Prefer32Bit was introduced in .NET 4.5. Set it to false if we are targeting 4.0 -->
|
||||
<PropertyGroup Condition="('$(TargetFrameworkVersion)' == 'v4.0')">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(UseSharedCompilation)' == ''">
|
||||
<UseSharedCompilation>true</UseSharedCompilation>
|
||||
</PropertyGroup>
|
||||
|
||||
<Csc
|
||||
AllowUnsafeBlocks="$(AllowUnsafeBlocks)"
|
||||
ApplicationConfiguration="$(AppConfigForCompiler)"
|
||||
BaseAddress="$(BaseAddress)"
|
||||
CheckForOverflowUnderflow="$(CheckForOverflowUnderflow)"
|
||||
CodePage="$(CodePage)"
|
||||
DebugType="$(DebugType)"
|
||||
DefineConstants="$(DefineConstants)"
|
||||
DelaySign="$(DelaySign)"
|
||||
DisabledWarnings="$(NoWarn)"
|
||||
EmitDebugInformation="$(DebugSymbols)"
|
||||
EnvironmentVariables="$(CscEnvironment)"
|
||||
ErrorEndLocation="$(ErrorEndLocation)"
|
||||
ErrorLog="$(ErrorLog)"
|
||||
ErrorReport="$(ErrorReport)"
|
||||
FileAlignment="$(FileAlignment)"
|
||||
GenerateFullPaths="$(GenerateFullPaths)"
|
||||
HighEntropyVA="$(HighEntropyVA)"
|
||||
KeyContainer="$(KeyContainerName)"
|
||||
KeyFile="$(KeyOriginatorFile)"
|
||||
LangVersion="$(LangVersion)"
|
||||
NoConfig="true"
|
||||
NoLogo="$(NoLogo)"
|
||||
NoStandardLib="$(NoCompilerStandardLib)"
|
||||
NoWin32Manifest="$(NoWin32Manifest)"
|
||||
Optimize="$(Optimize)"
|
||||
OutputAssembly="@(_RazorIntermediateAssembly)"
|
||||
PdbFile="@(_RazorIntermediatePdb)"
|
||||
Platform="$(PlatformTarget)"
|
||||
Prefer32Bit="$(Prefer32Bit)"
|
||||
PreferredUILang="$(PreferredUILang)"
|
||||
References="@(RazorReferencePath)"
|
||||
ReportAnalyzer="$(ReportAnalyzer)"
|
||||
ResponseFiles="$(CompilerResponseFile)"
|
||||
Sources="@(_RazorGenerated)"
|
||||
SubsystemVersion="$(SubsystemVersion)"
|
||||
TargetType="Library"
|
||||
ToolExe="$(CscToolExe)"
|
||||
ToolPath="$(CscToolPath)"
|
||||
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
|
||||
UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)"
|
||||
UseSharedCompilation="$(UseSharedCompilation)"
|
||||
Utf8Output="$(Utf8Output)"
|
||||
VsSessionGuid="$(VsSessionGuid)"
|
||||
WarningLevel="$(WarningLevel)"
|
||||
WarningsAsErrors="$(WarningsAsErrors)"
|
||||
WarningsNotAsErrors="$(WarningsNotAsErrors)"
|
||||
Win32Icon="$(ApplicationIcon)"
|
||||
Win32Manifest="$(Win32Manifest)"
|
||||
Win32Resource="$(Win32Resource)">
|
||||
</Csc>
|
||||
|
||||
<ItemGroup>
|
||||
<FileWrites Include="@(_RazorIntermediateAssembly)" Condition="Exists('@(_RazorIntermediateAssembly)')" />
|
||||
<FileWrites Include="@(_RazorIntermediatePdb)" Condition="Exists('@(_RazorIntermediatePdb)')" />
|
||||
</ItemGroup>
|
||||
|
||||
</Target>
|
||||
|
||||
<Target Name="_CopyRazorAssemblies"
|
||||
AfterTargets="CopyFilesToOutputDirectory">
|
||||
|
||||
<!-- Copy the Razor dll -->
|
||||
<Copy
|
||||
SourceFiles="@(_RazorIntermediateAssembly)"
|
||||
DestinationFolder="$(OutDir)"
|
||||
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
|
||||
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
|
||||
Retries="$(CopyRetryCount)"
|
||||
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
|
||||
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
Condition="Exists('@(_RazorIntermediateAssembly)') and '$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
|
||||
|
||||
<Output TaskParameter="DestinationFiles" ItemName="_RazorAssembly"/>
|
||||
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
|
||||
|
||||
</Copy>
|
||||
|
||||
<Message Importance="High" Text="$(MSBuildProjectName) -> @(_RazorAssembly->'%(FullPath)')" Condition="Exists('@(_RazorIntermediateAssembly)') and '$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)'!='true'" />
|
||||
|
||||
<!-- Copy the Razor debug information file (.pdb), if any -->
|
||||
<Copy
|
||||
SourceFiles="$(_RazorIntermediatePdb)"
|
||||
DestinationFiles="@(_DebugSymbolsOutputPath)"
|
||||
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
|
||||
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
|
||||
Retries="$(CopyRetryCount)"
|
||||
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
|
||||
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
Condition="Exists('@(_RazorIntermediatePdb)') and '$(SkipCopyingSymbolsToOutputDirectory)' != 'true' and '$(CopyOutputSymbolsToOutputDirectory)'=='true'">
|
||||
|
||||
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
|
||||
|
||||
</Copy>
|
||||
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
<!--
|
||||
Targets supporting Razor MSBuild integration
|
||||
-->
|
||||
<Import Project="Microsoft.AspNetCore.Razor.Design.Compilation.targets" />
|
||||
|
||||
<Target Name="RazorGenerate" DependsOnTargets="$(RazorGenerateDependsOn)">
|
||||
</Target>
|
||||
|
||||
|
|
@ -9,7 +11,7 @@
|
|||
</Target>
|
||||
|
||||
<PropertyGroup Condition="'$(RazorCompileOnBuild)'=='true'">
|
||||
<BuildDependsOn>$(BuildDependsOn);RazorCompile</BuildDependsOn>
|
||||
<PrepareForRunDependsOn>RazorCompile;$(PrepareForRunDependsOn)</PrepareForRunDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
|
|
@ -29,10 +31,6 @@
|
|||
<_RazorTagHelperInputCache>$(IntermediateOutputPath)$(TargetName).TagHelpers.input.cache</_RazorTagHelperInputCache>
|
||||
<_RazorTagHelperOutputCache>$(IntermediateOutputPath)$(TargetName).TagHelpers.output.cache</_RazorTagHelperOutputCache>
|
||||
|
||||
<!-- Used to creating the final compiled Razor dll -->
|
||||
<_RazorIntermediateAssembly>$(IntermediateOutputPath)$(RazorTargetName).dll</_RazorIntermediateAssembly>
|
||||
<_RazorIntermediatePdb>$(IntermediateOutputPath)$(RazorTargetName).pdb</_RazorIntermediatePdb>
|
||||
|
||||
<!-- Used to locate our tools -->
|
||||
<_RazorGenerateToolAssembly>$(_RazorMSBuildRoot)tools\Microsoft.AspNetCore.Razor.GenerateTool.dll</_RazorGenerateToolAssembly>
|
||||
<_RazorTagHelperToolAssembly>$(_RazorMSBuildRoot)tools\Microsoft.AspNetCore.Razor.TagHelperTool.dll</_RazorTagHelperToolAssembly>
|
||||
|
|
@ -142,121 +140,4 @@
|
|||
<FileWrites Include="@(_RazorGenerated)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
What follows here was copied and modified from the XamlPreCompile target in
|
||||
Microsoft.CSharp.CurrentVersion.targets
|
||||
|
||||
The XamlPreCompile target must remain identical to
|
||||
the CoreCompile target in Microsoft.CSharp.Core.targets.
|
||||
Any updates to one must be made to the other.
|
||||
-->
|
||||
<Target
|
||||
Name="RazorCoreCompile"
|
||||
Inputs="$(MSBuildAllProjects);
|
||||
@(_RazorGenerated);
|
||||
@(_CoreCompileResourceInputs);
|
||||
$(ApplicationIcon);
|
||||
$(AssemblyOriginatorKeyFile);
|
||||
@(RazorReferencePath);"
|
||||
|
||||
Outputs="$(_RazorIntermediateAssembly)"
|
||||
Returns=""
|
||||
DependsOnTargets="_RazorResolveTagHelpers;RazorCoreGenerate">
|
||||
|
||||
<!-- These two compiler warnings are raised when a reference is bound to a different version
|
||||
than specified in the assembly reference version number. MSBuild raises the same warning in this case,
|
||||
so the compiler warning would be redundant. -->
|
||||
<PropertyGroup Condition="('$(TargetFrameworkVersion)' != 'v1.0') and ('$(TargetFrameworkVersion)' != 'v1.1')">
|
||||
<NoWarn>$(NoWarn);1701;1702</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- To match historical behavior, when inside VS11+ disable the warning from csc.exe indicating that no sources were passed in-->
|
||||
<NoWarn Condition=" '$(BuildingInsideVisualStudio)' == 'true' and '$(VisualStudioVersion)' != '' and '$(VisualStudioVersion)' > '10.0' ">$(NoWarn);2008</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetingClr2Framework)'=='true'">
|
||||
<ReferencePath>
|
||||
<EmbedInteropTypes/>
|
||||
</ReferencePath>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- If the user has specified AppConfigForCompiler, we'll use it. If they have not, but they set UseAppConfigForCompiler,
|
||||
then we'll use AppConfig -->
|
||||
<AppConfigForCompiler Condition="'$(AppConfigForCompiler)' == '' and '$(UseAppConfigForCompiler)' == 'true'">$(AppConfig)</AppConfigForCompiler>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Prefer32Bit was introduced in .NET 4.5. Set it to false if we are targeting 4.0 -->
|
||||
<PropertyGroup Condition="('$(TargetFrameworkVersion)' == 'v4.0')">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(UseSharedCompilation)' == ''">
|
||||
<UseSharedCompilation>true</UseSharedCompilation>
|
||||
</PropertyGroup>
|
||||
|
||||
<Csc
|
||||
AllowUnsafeBlocks="$(AllowUnsafeBlocks)"
|
||||
ApplicationConfiguration="$(AppConfigForCompiler)"
|
||||
BaseAddress="$(BaseAddress)"
|
||||
CheckForOverflowUnderflow="$(CheckForOverflowUnderflow)"
|
||||
CodePage="$(CodePage)"
|
||||
DebugType="$(DebugType)"
|
||||
DefineConstants="$(DefineConstants)"
|
||||
DelaySign="$(DelaySign)"
|
||||
DisabledWarnings="$(NoWarn)"
|
||||
EmitDebugInformation="$(DebugSymbols)"
|
||||
EnvironmentVariables="$(CscEnvironment)"
|
||||
ErrorEndLocation="$(ErrorEndLocation)"
|
||||
ErrorLog="$(ErrorLog)"
|
||||
ErrorReport="$(ErrorReport)"
|
||||
FileAlignment="$(FileAlignment)"
|
||||
GenerateFullPaths="$(GenerateFullPaths)"
|
||||
HighEntropyVA="$(HighEntropyVA)"
|
||||
KeyContainer="$(KeyContainerName)"
|
||||
KeyFile="$(KeyOriginatorFile)"
|
||||
LangVersion="$(LangVersion)"
|
||||
NoConfig="true"
|
||||
NoLogo="$(NoLogo)"
|
||||
NoStandardLib="$(NoCompilerStandardLib)"
|
||||
NoWin32Manifest="$(NoWin32Manifest)"
|
||||
Optimize="$(Optimize)"
|
||||
OutputAssembly="$(_RazorIntermediateAssembly)"
|
||||
PdbFile="$(_RazorIntermediatePdb)"
|
||||
Platform="$(PlatformTarget)"
|
||||
Prefer32Bit="$(Prefer32Bit)"
|
||||
PreferredUILang="$(PreferredUILang)"
|
||||
References="@(RazorReferencePath)"
|
||||
ReportAnalyzer="$(ReportAnalyzer)"
|
||||
ResponseFiles="$(CompilerResponseFile)"
|
||||
Sources="@(_RazorGenerated)"
|
||||
SubsystemVersion="$(SubsystemVersion)"
|
||||
TargetType="Library"
|
||||
ToolExe="$(CscToolExe)"
|
||||
ToolPath="$(CscToolPath)"
|
||||
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
|
||||
UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)"
|
||||
UseSharedCompilation="$(UseSharedCompilation)"
|
||||
Utf8Output="$(Utf8Output)"
|
||||
VsSessionGuid="$(VsSessionGuid)"
|
||||
WarningLevel="$(WarningLevel)"
|
||||
WarningsAsErrors="$(WarningsAsErrors)"
|
||||
WarningsNotAsErrors="$(WarningsNotAsErrors)"
|
||||
Win32Icon="$(ApplicationIcon)"
|
||||
Win32Manifest="$(Win32Manifest)"
|
||||
Win32Resource="$(Win32Resource)">
|
||||
<Output
|
||||
TaskParameter="OutputAssembly"
|
||||
ItemName="FileWrites" />
|
||||
</Csc>
|
||||
|
||||
<!-- Output the PDB and COPY of things to FileWrites -->
|
||||
<Message Importance="High" Text="$(TargetName) -> $([System.IO.Path]::GetFullPath('$(OutDir)$(RazorTargetName).dll'))" />
|
||||
<Copy
|
||||
SourceFiles="$(_RazorIntermediateAssembly)"
|
||||
DestinationFolder="$(OutDir)"
|
||||
SkipUnchangedFiles="true"/>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -69,5 +69,50 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.FileExists(result, IntermediateOutputPath, "SimplePages.dll");
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimplePages.PrecompiledViews.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_SkipsCopyingBinariesToOutputDirectory_IfCopyBuildOutputToOutputDirectory_IsUnset()
|
||||
{
|
||||
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true /p:CopyBuildOutputToOutputDirectory=false");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_SkipsCopyingBinariesToOutputDirectory_IfCopyOutputSymbolsToOutputDirectory_IsUnset()
|
||||
{
|
||||
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true /p:CopyOutputSymbolsToOutputDirectory=false");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
|
||||
Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task Build_Works_WhenSymbolsAreNotGenerated()
|
||||
{
|
||||
var result = await DotnetMSBuild("Build", "/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, OutputPath, "SimpleMvc.PrecompiledViews.dll");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.pdb");
|
||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue