Skip to content

Commit

Permalink
Move ProjectReference into a conditional import
Browse files Browse the repository at this point in the history
This makes the `ProjectReference` item itself completely undiscoverable for project systems that enumerate references using the MSBuild API that gets items regardless of condition, which appears to be how the legacy project system (csproj.dll) does it at least sometimes.

Fixes #1040
  • Loading branch information
AArnott committed Apr 9, 2024
1 parent 2d32d93 commit a5374f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
<Visible>false</Visible>
<PrivateAssets>all</PrivateAssets>
</NBGV_CachingProjectReference>

<!-- Declare a P2P so that "msbuild -graph -isolate" doesn't complain when we use the MSBuild task to invoke our inner shared project.
This causes a lot of problems (https://github.com/dotnet/Nerdbank.GitVersioning/issues?q=label%3Amsbuild-p2p+) with projects
that expect to understand all their own ProjectReferences though, so only define it when the user is running a graph build. -->
<ProjectReference Include="@(NBGV_CachingProjectReference)" Condition="'$(IsGraphBuild)'=='true'">
<NBGV_InnerProject>true</NBGV_InnerProject>
</ProjectReference>
</ItemGroup>

<!-- Declare a P2P so that "msbuild -graph -isolate" doesn't complain when we use the MSBuild task to invoke our inner shared project.
This causes a lot of problems (https://github.com/dotnet/Nerdbank.GitVersioning/issues?q=label%3Amsbuild-p2p+) with projects
that expect to understand all their own ProjectReferences though, so only define it when the user is running a graph build.
Rather than condition the item (which the legacy project system 'sees through' using MSBuild APIs),
we condition an import so that the item will be utterly undiscoverable by the project system. -->
<Import Project="ProjectReferenceForGraphBuild.targets" Condition="'$(IsGraphBuild)'=='true'"/>

<Target Name="InvokeGetBuildVersionTask">
<Error Text="BuildMetadata items changed after a copy was made. Add all BuildMetadata items before importing this file." Condition=" '@(BuildMetadata)' != '@(_BuildMetadataSnapped)' " />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<ProjectReference Include="@(NBGV_CachingProjectReference)">
<NBGV_InnerProject>true</NBGV_InnerProject>
</ProjectReference>
</ItemGroup>
</Project>

0 comments on commit a5374f0

Please sign in to comment.