Introduce a Razor SDK package

Move parts of Razor.Design in to an SDK that ship with the CLI.
This commit is contained in:
Pranav K 2018-01-23 18:08:22 -08:00
parent 771a7e35a4
commit 04bf7eec0f
14 changed files with 166 additions and 64 deletions

View File

@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27107.3000
MinimumVisualStudioVersion = 15.0.26730.03
@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Razo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Tools", "src\Microsoft.AspNetCore.Razor.Tools\Microsoft.AspNetCore.Razor.Tools.csproj", "{3E7F2D49-3B45-45A8-9893-F73EC1EEBAAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Razor.Sdk", "src\Microsoft.AspNetCore.Razor.Sdk\Microsoft.AspNetCore.Razor.Sdk.csproj", "{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -378,6 +380,14 @@ Global
{3E7F2D49-3B45-45A8-9893-F73EC1EEBAAB}.Release|Any CPU.Build.0 = Release|Any CPU
{3E7F2D49-3B45-45A8-9893-F73EC1EEBAAB}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{3E7F2D49-3B45-45A8-9893-F73EC1EEBAAB}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.Release|Any CPU.Build.0 = Release|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.ReleaseNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9}.ReleaseNoVSIX|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -418,6 +428,7 @@ Global
{6205467F-E381-4C42-AEEC-763BD62B3D5E} = {C2C98051-0F39-47F2-80B6-E72B29159F2C}
{933101DA-C4CC-401A-AA01-2784E1025B7F} = {92463391-81BE-462B-AC3C-78C6C760741F}
{3E7F2D49-3B45-45A8-9893-F73EC1EEBAAB} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED}
{7D9ECCEE-71D1-4A42-ABEE-876AFA1B4FC9} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0035341D-175A-4D05-95E6-F1C2785A1E26}

View File

@ -5,13 +5,6 @@
<PropertyGroup>
<Description>Razor is a markup syntax for adding server-side logic to web pages. This package contains MSBuild support for Razor.</Description>
<!--
Using netcoreapp2.0 here is a workaround for https://github.com/Microsoft/msbuild/issues/2661
We need to use a P2P reference to build some other projects that need to target netcoreapp2.0
and even though we don't actually want to reference the output, MSBuild will not allow it.
-->
<TargetFramework>netstandard2.0</TargetFramework>
<!-- This project doesn't have any code, so don't include it in the .nupkg -->
@ -108,4 +101,4 @@
<Error Text="_RazorTool is empty. This is a bug" Condition="'@(_RazorTool)'==''" />
</Target>
</Project>
</Project>

View File

@ -1,6 +1,7 @@
<Project>
<!--
Targets used for Razor SDK code generation. Support for the RazorCoreGenerate target.
This target is explicitly imported by Razor SDK.
-->
<!--
@ -27,7 +28,6 @@
-->
<Target
Name="_HashRazorGenerateInputs"
AfterTargets="ResolveRazorGenerateInputs"
Condition="'@(RazorGenerate)'!=''">
<Hash ItemsToHash="@(RazorGenerate)">
@ -83,14 +83,22 @@
</RazorTagHelper>
</Target>
<Target Name="_ResolveRazorGenerateOutputs" AfterTargets="PrepareForRazorGenerate">
<Target Name="_ResolveRazorGenerateOutputs">
<ItemGroup>
<_RazorGenerateOutput Include="%(RazorGenerate.GeneratedOutput)" Condition="'%(RazorGenerate.GeneratedOutput)'!=''"/>
</ItemGroup>
</Target>
<PropertyGroup>
<RazorCoreGenerateDependsOn>
_HashRazorGenerateInputs;
_ResolveRazorGenerateOutputs;
</RazorCoreGenerateDependsOn>
</PropertyGroup>
<Target
Name="RazorCoreGenerate"
DependsOnTargets="$(RazorCoreGenerateDependsOn)"
Inputs="$(MSBuildAllProjects);$(_RazorGenerateInputsHashFile);$(_RazorTagHelperOutputCache);@(RazorGenerate)"
Outputs="@(_RazorGenerateOutput)"
Condition="'@(RazorGenerate)'!= ''">
@ -118,7 +126,11 @@
</ItemGroup>
</Target>
<Target Name="_ResolveGeneratedRazorCompileInputs" BeforeTargets="ResolveRazorCompileInputs">
<PropertyGroup>
<ResolveRazorCompileInputsDependsOn>$(ResolveRazorCompileInputsDependsOn);_ResolveGeneratedRazorCompileInputs</ResolveRazorCompileInputsDependsOn>
</PropertyGroup>
<Target Name="_ResolveGeneratedRazorCompileInputs">
<ItemGroup>
<RazorCompile Include="@(_RazorGenerateOutput)" />
<RazorEmbeddedResource Include="@(RazorGenerate)" Condition="$(EmbedRazorGenerateSources)">
@ -136,4 +148,4 @@
</ItemGroup>
</Target>
</Project>
</Project>

View File

@ -1,50 +1,18 @@
<Project TreatAsLocalProperty="_RazorTaskFolder;_RazorTaskAssembly">
<!--
Properties and tasks supporting Razor MSBuild integration
-->
<!--
Default properties for common Razor SDK behavior.
-->
<PropertyGroup>
<!--
Set to true to automatically include Razor (.cshtml) files in @(RazorGenerate) from @(Content).
-->
<EnableDefaultRazorGenerateItems Condition="'$(EnableDefaultRazorGenerateItems)'==''">true</EnableDefaultRazorGenerateItems>
<!--
Set to true to copy RazorGenerate items (.cshtml) to the publish directory.
Typically Razor files are not needed for a published application if they participate in compilation at build-time
or publish-time. By default, the Razor SDK will suppress the copying of RazorGenerate items to the publish directory.
-->
<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>
</PropertyGroup>
<!--
Razor also attaches itself by default to some of the standard .NET targets. Uses these properties to
configure this behaviour.
-->
<PropertyGroup>
<RazorGenerateDependsOn>RazorResolveGenerateInputs;RazorCoreGenerate</RazorGenerateDependsOn>
<RazorCompileDependsOn>RazorGenerate;RazorCoreCompile</RazorCompileDependsOn>
</PropertyGroup>
<PropertyGroup>
<!--
Used by the Web SDK to know if the Razor SDK is present. This needs to live in a nuget package (not in the SDK)
so that it only shows up in supported versions.
Used by the Web SDK if the Razor SDK can be used for compilation. This needs to live in a nuget package (not in the SDK)
so that it only shows up in supported versions.
-->
<IsRazorCompilerReferenced>true</IsRazorCompilerReferenced>
<!--
Location of the CodeGeneration targets. The SDK uses this to import the file ensuring deterministic import order.
-->
<RazorCodeGenerationTargetsPath>$(MSBuildThisFileDirectory)Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets</RazorCodeGenerationTargetsPath>
</PropertyGroup>
<PropertyGroup>
<!-- Override this to hijack the tasks and targets. Used by tests. -->
<_RazorMSBuildRoot Condition="'$(_RazorMSBuildRoot)'==''">$(MSBuildThisFileDirectory)..\..\</_RazorMSBuildRoot>

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Razor is a markup syntax for adding server-side logic to web pages. This package contains MSBuild support for Razor.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- This project doesn't have any code, so don't include it in the .nupkg -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<EnableDefaultItems>false</EnableDefaultItems>
<EnableApiCheck>false</EnableApiCheck>
</PropertyGroup>
<ItemGroup>
<None Include="SDK\*" Pack="true" PackagePath="SDK\" />
<None Include="build\**\*" Pack="true" PackagePath="build" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@
<!--
***********************************************************************************************
Sdk.props
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)..\build\netstandard2.0\Razor.Sdk.CurrentVersion.props" />
</Project>

View File

@ -0,0 +1,20 @@
<!--
***********************************************************************************************
Sdk.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(_RazorSdkCurrentVersionPath)"
Condition="'$(_RazorSdkCurrentVersionPath)' != '' AND Exists('$(_RazorSdkCurrentVersionPath)')" />
<Import Project="$(MSBuildThisFileDirectory)..\build\netstandard2.0\Razor.Sdk.CurrentVersion.targets"
Condition="'$(MicrosoftAspNetCoreRazorSdkTargetsImported)' != 'true'" />
</Project>

View File

@ -1,7 +1,7 @@
<Project>
<!--
What follows in this file is based on:
https://github.com/dotnet/roslyn/blob/4d92b18aee99ba8b1b4770ce65133e9ca65a94fe/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
https://github.com/dotnet/roslyn/blob/4d92b18aee99ba8b1b4770ce65133e9ca65a94fe/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
We need to keep this basically up to date, as well as track the set of modifications we've made. Try to keep the formatting
similar to the original to reduce noise. In general try to only deviate from the CoreCompile target when we need to for
@ -12,7 +12,7 @@
Changes:
Name="RazorCoreCompile"
Replace @(Compile) with @(RazorCompile)
Replace @(_DebugSymbolsIntermediatePath) with @(_RazorDebugSymbolsIntermediatePath)
Replace @(IntermediateAssembly) with @(RazorIntermediateAssembly)
@ -22,7 +22,7 @@
Set TargetType="$(OutputType)" to TargetType="Library" - Razor is always a .dll
Remove Returns="@(CscCommandLineArgs)"
Remove @(EmbeddedFiles)
Remove $(ApplicationIcon) $(Win32Resource) $(Win32Manifest)
Remove @(EmbeddedDocumentation) and @(EmbeddedFiles)

View File

@ -0,0 +1,8 @@
<Project>
<Import Project="Sdk.CurrentVersion.props" />
<PropertyGroup>
<!-- Redirect the SDK to use the targets from the current package -->
<_RazorSdkCurrentVersionPath>$(MSBuildFileDirectory)Sdk.CurrentVersion.targets</_RazorSdkCurrentVersionPath>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,3 @@
<Project>
<Import Project="Sdk.CurrentVersion.targets" />
</Project>

View File

@ -0,0 +1,37 @@
<Project>
<!--
Properties and tasks supporting Razor MSBuild integration
-->
<!--
Default properties for common Razor SDK behavior.
-->
<PropertyGroup>
<!--
Set to true to automatically include Razor (.cshtml) files in @(RazorGenerate) from @(Content).
-->
<EnableDefaultRazorGenerateItems Condition="'$(EnableDefaultRazorGenerateItems)'==''">true</EnableDefaultRazorGenerateItems>
<!--
Set to true to copy RazorGenerate items (.cshtml) to the publish directory.
Typically Razor files are not needed for a published application if they participate in compilation at build-time
or publish-time. By default, the Razor SDK will suppress the copying of RazorGenerate items to the publish directory.
-->
<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>
</PropertyGroup>
<PropertyGroup>
<!-- This property is used by the SDK package to redirect the location of Sdk.CurrentVersion.targets -->
<_RazorSdkCurrentVersionPath>$(MSBuildThisFileDirectory)Sdk.CurrentVersions.target</_RazorSdkCurrentVersionPath>
</PropertyGroup>
</Project>

View File

@ -10,6 +10,10 @@
-->
<Import Project="$(CustomBeforeRazorSdkTargets)" Condition="'$(CustomBeforeRazorSdkTargets)' != '' and Exists('$(CustomBeforeRazorSdkTargets)')"/>
<PropertyGroup>
<MicrosoftAspNetCoreRazorSdkTargetsImported>true</MicrosoftAspNetCoreRazorSdkTargetsImported>
</PropertyGroup>
<!--
Razor defines two primary targets:
'RazorGenerate' - which updates generated code
@ -21,19 +25,24 @@
<PrepareForRazorGenerateDependsOn>
ResolveRazorGenerateInputs;
ResolveAssemblyReferenceRazorGenerateInputs;
_EnsureRazorCompilerReferenced;
ResolveTagHelperRazorGenerateInputs
</PrepareForRazorGenerateDependsOn>
<RazorGenerateDependsOn>
PrepareForRazorGenerate;
_EnsureRazorCompilerReferenced;
RazorCoreGenerate
</RazorGenerateDependsOn>
<PrepareForRazorCompileDependsOn>
RazorGenerate;
ResolveRazorCompileInputs;
ResolveRazorCompileInputs
</PrepareForRazorCompileDependsOn>
<ResolveRazorCompileInputsDependsOn>
</ResolveRazorCompileInputsDependsOn>
<RazorCompileDependsOn>
PrepareForRazorCompile;
RazorCoreCompile
@ -123,10 +132,10 @@
<!--
These are the targets that generate code using Razor, separated from the main file for ease of maintenance.
Most targets related to Razor code generation are defined there.
-->
<Import Project="Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets" />
<Import Project="$(RazorCodeGenerationTargetsPath)"
Condition="'$(RazorCodeGenerationTargetsPath)' != '' AND Exists('$(RazorCodeGenerationTargetsPath)')" />
<!--
These are the targets that actually do compilation using CSC, separated from the main file for ease of maintenance.
@ -192,7 +201,7 @@
This is marker target so that the code generation targets can attach.
-->
<Target Name="ResolveRazorCompileInputs">
<Target Name="ResolveRazorCompileInputs" DependsOnTargets="$(ResolveRazorCompileInputsDependsOn)">
</Target>
<!--
@ -374,6 +383,11 @@
</Target>
<Target Name="_EnsureRazorCompilerReferenced" Condition="'$(IsRazorCompilerReferenced)' != 'true'">
<Error Text="A reference to Microsoft.AspNetCore.Razor.Design is required for this target to succeed. See todo:fwlink for instructions on how to resolve this." />
</Target>
<!--
This is a hook to import a set of targets after the Razor targets. By default this is unused.
-->

View File

@ -31,7 +31,8 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
if (string.IsNullOrEmpty(BuildVariables.MSBuildPath))
{
throw new ArgumentException("Unable to locate MSBuild.exe to run desktop tests.");
throw new ArgumentException("Unable to locate MSBuild.exe to run desktop tests. " +
"MSBuild.exe is located using state created as part of running build[cmd|sh] at the root of the repository. Run build /t:Prepeare to set this up if this hasn't been done.");
}
processStartInfo.FileName = BuildVariables.MSBuildPath;

View File

@ -98,6 +98,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
var text = $@"
<Project>
<Import Project=""{originalProjectRoot}\..\..\..\src\Microsoft.AspNetCore.Razor.Sdk\SDK\Sdk.props""/>
<PropertyGroup>
<OriginalProjectRoot>{originalProjectRoot}</OriginalProjectRoot>
<BinariesRoot>{binariesRoot}</BinariesRoot>
@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
var text = $@"
<Project>
<Import Project=""$(OriginalProjectRoot)\..\..\..\src\Microsoft.AspNetCore.Razor.Design\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.targets""/>
<Import Project=""$(OriginalProjectRoot)\..\..\..\src\Microsoft.AspNetCore.Razor.Sdk\SDK\Sdk.targets""/>
</Project>
";
File.WriteAllText(Path.Combine(projectRoot, "Directory.Build.targets"), text);