Skip to content

Commit 5038d77

Browse files
committed
Ensure only direct dependencies are exposed as analyzer props
See https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets#L566 We need to filter the restore graph by the ProjectUniqueName that matches the current project, since P2P references bring the transitive graph. Analyzers can now check for an analyzer option property named `build_property.My_Package` (for a package named `My.Package`).
1 parent dbf1cb0 commit 5038d77

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

samples/dotnet/SponsorLink/buildTransitive/Devlooped.Sponsors.targets

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@
4444
<!-- Makes direct dependencies visible to the compiler, so that sponsoring checks can selectively skip indirectly referenced analyzer -->
4545
<!-- An analyzer can check for the presense of a global property named after the package id (which will contain the instaled version) -->
4646
<ItemGroup>
47-
<CompilerVisibleProperty Include="$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.Id)', '').Replace('.', '_'))" />
47+
<DirectDependency Include="@(_RestoreGraphEntry -> HasMetadata('Id'))"
48+
Condition="'%(_RestoreGraphEntry.Type)' == 'Dependency' and
49+
'%(_RestoreGraphEntry.ProjectUniqueName)' == '$(MSBuildProjectFullPath)'">
50+
<Id>$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.Id)', '').Replace('.', '_'))</Id>
51+
</DirectDependency>
52+
<CompilerVisibleProperty Include="@(DirectDependency -> '%(Id)')" />
4853
</ItemGroup>
49-
<CreateProperty Value="%(_RestoreGraphEntry.VersionRange)" Condition="%(_RestoreGraphEntry.Type) == 'Dependency'" >
50-
<Output TaskParameter="Value" PropertyName="$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.Id)', '').Replace('.', '_'))"/>
54+
<CreateProperty Condition="'@(DirectDependency)' != ''" Value="%(DirectDependency.VersionRange)">
55+
<Output TaskParameter="Value" PropertyName="%(DirectDependency.Id)"/>
5156
</CreateProperty>
5257
</Target>
5358

0 commit comments

Comments
 (0)