Skip to content

Commit 3b67abe

Browse files
authored
Add an MSBuild target to set MsBuild.exe path (#6401)
* Add an MSBuild target to set MsBuild.exe path * Added a warning message * Don't build Razor.Tasks twice * Compile include inside the target
1 parent 1677ed2 commit 3b67abe

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/Razor/Razor.Design/src/Microsoft.AspNetCore.Razor.Design.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
3636

3737
<PropertyGroup>
38-
<GenerateNuspecDependsOn>_BuildDependencyProjects;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
3938
<BuildDependsOn>_BuildDependencyProjects;$(BuildDependsOn)</BuildDependsOn>
4039
</PropertyGroup>
4140

@@ -92,7 +91,7 @@
9291
<Error Text="_RazorTool is empty. This is a bug" Condition="'@(_RazorTool)'==''" />
9392
</Target>
9493

95-
<Target Name="PopulateNuspec" BeforeTargets="GenerateNuspec" DependsOnTargets="BuiltProjectOutputGroup;DebugSymbolsProjectOutputGroup;_BuildDependencyProjects">
94+
<Target Name="PopulateNuspec" BeforeTargets="GenerateNuspec" DependsOnTargets="BuiltProjectOutputGroup;DebugSymbolsProjectOutputGroup">
9695

9796
<PropertyGroup>
9897
<!-- Make sure we create a symbols.nupkg. -->

src/Razor/Razor.Design/test/IntegrationTests/Microsoft.AspNetCore.Razor.Design.Test.csproj

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
<!-- Copy references locally so that we can use them in the test. -->
1414
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1515
<BuildVariablesGeneratedFile>$(MSBuildProjectDirectory)\obj\BuildVariables.generated.cs</BuildVariablesGeneratedFile>
16-
<CompileDependsOn>EnsureBuildVariablesGeneratedFile;$(CompileDependsOn)</CompileDependsOn>
1716
</PropertyGroup>
1817

1918
<ItemGroup>
2019
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
21-
<Compile Include="$(BuildVariablesGeneratedFile)" Condition="Exists('$(BuildVariablesGeneratedFile)')" />
2220
</ItemGroup>
2321

2422
<!-- The test projects rely on these binaries being available -->
@@ -35,8 +33,31 @@
3533
<Reference Include="Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib" />
3634
</ItemGroup>
3735

38-
<Target Name="EnsureBuildVariablesGeneratedFile">
39-
<Error Text="BuildVariables.generated.cs was not found. Run .\build /t:Prepare from the root of the repository to generate it." Condition="!Exists('$(BuildVariablesGeneratedFile)')" />
36+
<Target Name="GenerateBuildVariablesFile" BeforeTargets="BeforeBuild">
37+
<Warning Text="Some SDK tests on Windows require the project to be built once using Desktop MSBuild, but the current build is executed using .NET Core MSBuild. This may result in test failures."
38+
Condition="!Exists('$(BuildVariablesGeneratedFile)') and '$(MSBuildRuntimeType)' != 'Full' and '$(OS)' == 'Windows_NT'" />
39+
40+
<PropertyGroup>
41+
<GeneratedFileContents>
42+
// Copyright (c) .NET Foundation. All rights reserved.
43+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
44+
45+
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
46+
{
47+
internal static partial class BuildVariables
48+
{
49+
static partial void InitializeVariables()
50+
{
51+
_msBuildPath = @"$(MSBuildBinPath)\MSBuild.exe"%3B
52+
}
53+
}
54+
}
55+
</GeneratedFileContents>
56+
</PropertyGroup>
57+
<WriteLinesToFile Lines="$(GeneratedFileContents)" File="$(BuildVariablesGeneratedFile)" Overwrite="true" WriteOnlyWhenDifferent="true" Condition="'$(MSBuildRuntimeType)' == 'Full'" />
58+
<ItemGroup>
59+
<Compile Include="$(BuildVariablesGeneratedFile)" Condition="Exists('$(BuildVariablesGeneratedFile)')" />
60+
</ItemGroup>
4061
</Target>
4162

4263
</Project>

0 commit comments

Comments
 (0)