Skip to content

Commit fdbe652

Browse files
committed
Use chaining for custom .targets
1 parent 1b6641a commit fdbe652

4 files changed

Lines changed: 11 additions & 16 deletions

File tree

ComputeSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.GlobalSt
102102
EndProject
103103
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B86A48A7-18BD-4946-B995-3CE26B092DDF}"
104104
ProjectSection(SolutionItems) = preProject
105-
src\Directory.Build.BeforeMicrosoftCommon.targets = src\Directory.Build.BeforeMicrosoftCommon.targets
105+
src\Directory.Build.BeforeMicrosoftNETSdkTargets.targets = src\Directory.Build.BeforeMicrosoftNETSdkTargets.targets
106106
src\Directory.Build.props = src\Directory.Build.props
107107
src\Directory.Build.targets = src\Directory.Build.targets
108108
EndProjectSection

src/Directory.Build.BeforeMicrosoftCommon.targets renamed to src/Directory.Build.BeforeMicrosoftNETSdkTargets.targets

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040

4141
<!-- Add a marker value to verify from a later .targets that this .targets has been correctly invoked -->
4242
<PropertyGroup>
43-
<_ComputeSharpCustomBeforeMicrosoftCommonTargetsValid>true</_ComputeSharpCustomBeforeMicrosoftCommonTargetsValid>
43+
<_ComputeSharpBeforeMicrosoftNETSdkTargetsValid>true</_ComputeSharpBeforeMicrosoftNETSdkTargetsValid>
4444
</PropertyGroup>
45-
46-
<!-- Import the original custom .targets, if it exists -->
47-
<Import Project="$(_ComputeSharpCustomBeforeMicrosoftCommonTargets)"
48-
Condition="'$(_ComputeSharpCustomBeforeMicrosoftCommonTargets)' != '' AND Exists('$(_ComputeSharpCustomBeforeMicrosoftCommonTargets)')"/>
4945
</Project>

src/Directory.Build.props

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@
8585
</ItemGroup>
8686

8787
<!--
88-
Setup the custom .targets to run as 'CustomBeforeMicrosoftCommonTargets'. We also make a copy of the original value so
89-
that we can manually import it ourselves after ours. This is because we want to be able to read properties that are set
90-
in .csproj files, and set properties depending on those before the .NET SDK .targets are imported. This is necessary
91-
to ensure that the .NET tooling works correctly with some of them (eg. with 'IsAotCompatible').
88+
Setup the custom .targets to run as 'BeforeMicrosoftNETSdkTargets'. This is because we want to be able to read properties
89+
that are set in .csproj files, and set properties depending on those before the .NET SDK .targets are imported. This is
90+
necessary to ensure that the .NET tooling works correctly with some of them (eg. with 'IsAotCompatible'). Note that the
91+
.NET SDK doesn't use 'Exists' here, and '<Import>' supports multiple items, so we can just chain our .targets file directly.
9292
-->
9393
<PropertyGroup>
94-
<_ComputeSharpCustomBeforeMicrosoftCommonTargets>$(CustomBeforeMicrosoftCommonTargets)</_ComputeSharpCustomBeforeMicrosoftCommonTargets>
95-
<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)Directory.Build.BeforeMicrosoftCommon.targets</CustomBeforeMicrosoftCommonTargets>
94+
<BeforeMicrosoftNETSdkTargets>$(BeforeMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)Directory.Build.BeforeMicrosoftNETSdkTargets.targets</BeforeMicrosoftNETSdkTargets>
9695
</PropertyGroup>
9796
</Project>

src/Directory.Build.targets

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
</ItemGroup>
7979
</Target>
8080

81-
<!-- Emit an error if our custom 'BeforeCommon' .targets file has not been invoked -->
82-
<Target Name="_ComputeSharpCheckForInvalidCustomBeforeMicrosoftCommonTargets"
81+
<!-- Emit an error if our custom 'BeforeMicrosoftNETSdkTargets' .targets file has not been invoked -->
82+
<Target Name="_ComputeSharpCheckForInvalidBeforeMicrosoftNETSdkTargets"
8383
BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile">
84-
<Error Condition ="'$(_ComputeSharpCustomBeforeMicrosoftCommonTargetsValid)' != 'true'"
85-
Text="The '_ComputeSharpCustomBeforeMicrosoftCommonTargetsValid' marker property is not set."/>
84+
<Error Condition ="'$(_ComputeSharpBeforeMicrosoftNETSdkTargetsValid)' != 'true'"
85+
Text="The '_ComputeSharpBeforeMicrosoftNETSdkTargetsValid' marker property is not set."/>
8686
</Target>
8787
</Project>

0 commit comments

Comments
 (0)