Skip to content

Commit

Permalink
Use chaining for custom .targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 24, 2024
1 parent 1aa7077 commit a32b58c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/Directory.Build.BeforeMicrosoftCommon.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@
<PropertyGroup>
<_ComputeSharpCustomBeforeMicrosoftCommonTargetsValid>true</_ComputeSharpCustomBeforeMicrosoftCommonTargetsValid>
</PropertyGroup>

<!-- Import the original custom .targets, if it exists -->
<Import Project="$(_ComputeSharpCustomBeforeMicrosoftCommonTargets)"
Condition="'$(_ComputeSharpCustomBeforeMicrosoftCommonTargets)' != '' AND Exists('$(_ComputeSharpCustomBeforeMicrosoftCommonTargets)')"/>
</Project>
11 changes: 5 additions & 6 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@
</ItemGroup>

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

0 comments on commit a32b58c

Please sign in to comment.