Skip to content

Commit 11c8ad4

Browse files
author
John Luo
authored
Consolidate RazorSdkDirectory logic (#22836)
* Consolidate RazorSdkDirectory logic
1 parent a2162e5 commit 11c8ad4

File tree

7 files changed

+39
-34
lines changed

7 files changed

+39
-34
lines changed

eng/targets/CSharp.Common.props

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,24 @@
1414
<PackageReference Condition="'$(DotNetBuildFromSource)' != 'true'" Include="Microsoft.DotNet.GenAPI" PrivateAssets="All" Version="$(MicrosoftDotNetGenApiPackageVersion)" IsImplicitlyDefined="true" />
1515
</ItemGroup>
1616

17-
<Choose>
18-
<When Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''">
19-
<ItemGroup>
20-
<!--
21-
Use the Razor SDK as a project reference. The version of the .NET Core SDK we build with often contains a version of the Razor SDK
22-
several versions older than latest. We reference the project to ensure it's built before the other projects that use it. Since this
23-
is a project reference, we must explicitly import the props file and also specify the output location of the SDK directory.
24-
-->
25-
<ProjectReference Include="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\Microsoft.NET.Sdk.Razor.csproj"
26-
PrivateAssets="All"
27-
IsImplicitlyDefined="true"
28-
ReferenceOutputAssembly="false"
29-
SkipGetTargetFrameworkProperties="true"
30-
UndefineProperties="TargetFramework;TargetFrameworks" />
31-
</ItemGroup>
32-
33-
<PropertyGroup>
34-
<RazorSdkDirectoryRoot>$(ArtifactsBinDir)Microsoft.NET.Sdk.Razor\$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
35-
</PropertyGroup>
36-
</When>
37-
</Choose>
38-
39-
<Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
17+
<ItemGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''">
18+
<!--
19+
Use the Razor SDK as a project reference. The version of the .NET Core SDK we build with often contains a version of the Razor SDK
20+
several versions older than latest. We reference the project to ensure it's built before the other projects that use it. Since this
21+
is a project reference, we must explicitly import the props file and also specify the output location of the SDK directory.
22+
-->
23+
<ProjectReference Include="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\Microsoft.NET.Sdk.Razor.csproj"
24+
PrivateAssets="All"
25+
IsImplicitlyDefined="true"
26+
ReferenceOutputAssembly="false"
27+
SkipGetTargetFrameworkProperties="true"
28+
UndefineProperties="TargetFramework;TargetFrameworks" />
29+
</ItemGroup>
4030

31+
<ImportGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''">
32+
<Import Project="$(RepoRoot)eng\targets\GetRazorSDKDirectory.props" />
33+
<Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" />
34+
</ImportGroup>
4135

4236
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
4337
<Reference Include="Microsoft.AspNetCore.Testing" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<RazorSdkDirectoryRoot Condition="'$(RazorSdkDirectoryRoot)' == ''">$(ArtifactsBinDir)Microsoft.NET.Sdk.Razor\$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
4+
</PropertyGroup>
5+
</Project>

src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
<_Parameter2>$(TargetFramework)</_Parameter2>
6969
<_Parameter3></_Parameter3>
7070
</AssemblyAttribute>
71+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
72+
<_Parameter1>Test.RazorSdkDirectoryRoot</_Parameter1>
73+
<_Parameter2>$(RazorSdkDirectoryRoot)</_Parameter2>
74+
</AssemblyAttribute>
7175
</ItemGroup>
7276

7377
<Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">

src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/TemplateTests.props.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,4 @@
3535
Since this is a project reference, we must explicitly import the props file and also specify the output location of the SDK directory.
3636
-->
3737
<Import Project="${RepoRoot}src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
38-
39-
<PropertyGroup>
40-
<RazorSdkDirectoryRoot>${ArtifactsBinDir}Microsoft.NET.Sdk.Razor\${Configuration}\sdk-output\</RazorSdkDirectoryRoot>
41-
</PropertyGroup>
4238
</Project>

src/ProjectTemplates/Shared/Project.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class Project : IDisposable
3939
public string ProjectGuid { get; set; }
4040
public string TemplateOutputDir { get; set; }
4141
public string TargetFramework { get; set; } = GetAssemblyMetadata("Test.DefaultTargetFramework");
42+
public string RazorSdkDirectoryRoot { get; set; } = GetAssemblyMetadata("Test.RazorSdkDirectoryRoot");
4243

4344
public string TemplateBuildDir => Path.Combine(TemplateOutputDir, "bin", "Debug", TargetFramework);
4445
public string TemplatePublishDir => Path.Combine(TemplateOutputDir, "bin", "Release", TargetFramework, "publish");
@@ -116,7 +117,9 @@ internal async Task<ProcessResult> RunDotNetPublishAsync(IDictionary<string, str
116117
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
117118
// should avoid any global contention and we can execute a build or publish in a lock-free way
118119

119-
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish --no-restore -c Release /bl {additionalArgs}", packageOptions);
120+
var razorSDKarg = string.IsNullOrEmpty(RazorSdkDirectoryRoot) ? string.Empty : $"/p:RazorSdkDirectoryRoot={RazorSdkDirectoryRoot}";
121+
122+
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish --no-restore -c Release /bl {razorSDKarg} {additionalArgs}", packageOptions);
120123
await result.Exited;
121124
CaptureBinLogOnFailure(result);
122125
return new ProcessResult(result);
@@ -129,7 +132,9 @@ internal async Task<ProcessResult> RunDotNetBuildAsync(IDictionary<string, strin
129132
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
130133
// should avoid any global contention and we can execute a build or publish in a lock-free way
131134

132-
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {additionalArgs}", packageOptions);
135+
var razorSDKarg = string.IsNullOrEmpty(RazorSdkDirectoryRoot) ? string.Empty : $"/p:RazorSdkDirectoryRoot={RazorSdkDirectoryRoot}";
136+
137+
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {razorSDKarg} {additionalArgs}", packageOptions);
133138
await result.Exited;
134139
CaptureBinLogOnFailure(result);
135140
return new ProcessResult(result);

src/ProjectTemplates/test/Infrastructure/TemplateTests.props.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,5 @@
3434
We reference the project to ensure it's built before the other projects that use it. Since this is a project reference, we
3535
must explicitly import the props file and also specify the output location of the SDK directory.
3636
-->
37-
<Import Project="${RepoRoot}src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
38-
39-
<PropertyGroup>
40-
<RazorSdkDirectoryRoot>${ArtifactsBinDir}Microsoft.NET.Sdk.Razor\${Configuration}\sdk-output\</RazorSdkDirectoryRoot>
41-
</PropertyGroup>
37+
<Import Project="${RepoRoot}src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
4238
</Project>

src/ProjectTemplates/test/ProjectTemplates.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<!-- Shared testing infrastructure for running E2E tests using selenium -->
44
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.props" />
5+
<Import Project="$(RepoRoot)eng\targets\GetRazorSDKDirectory.props" Condition="'$(IsHelixJob)' != 'true'"/>
56

67
<PropertyGroup>
78
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
@@ -61,6 +62,10 @@
6162
<_Parameter1>Test.DefaultTargetFramework</_Parameter1>
6263
<_Parameter2>$(DefaultNetCoreTargetFramework)</_Parameter2>
6364
</AssemblyAttribute>
65+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
66+
<_Parameter1>Test.RazorSdkDirectoryRoot</_Parameter1>
67+
<_Parameter2>$(RazorSdkDirectoryRoot)</_Parameter2>
68+
</AssemblyAttribute>
6469
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
6570
<_Parameter1>ContinuousIntegrationBuild</_Parameter1>
6671
<_Parameter2>true</_Parameter2>

0 commit comments

Comments
 (0)