Skip to content

Commit 84a2483

Browse files
committed
Ensure private assets always for NuGetizer
Since analyzers are transitive by default (unless PrivateAssets=all in the PackageReference), we could have been inadvertently running SL checks via project-to-project (P2P) references and causing build errors since SL requires some compiler-visible properties surfaced via MSBuild that would otherwise not be available. This can happen if you add a package reference manually and forget to set PrivateAssets=all. But NuGetizer is *always* intended to be private assets. After some testing, it turns out that even if we set the PrivateAssets=all via targets provided by the package itself, we can prevent this abnormal (but perhaps easy to encounter?) situation from happening at all. This is particularly necessary with the introduction of the SponsorLink checks, since those are analyzers too, and require compiler-visible properties to be surfaced. By forcing PrivateAssets, we make sure SponsorLink analyzer never runs on P2P projects and only on the directly referencing one.
1 parent ec664c9 commit 84a2483

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/NuGetizer.Tasks/NuGetizer.Inference.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Copyright (c) .NET Foundation. All rights reserved.
195195
<ItemGroup>
196196
<!-- NuGetizer should never pack transitively (i.e. SponsorLink assets), even
197197
when PrivateAssets=all is used due to being a development dependency now. -->
198-
<PackageReference Update="NuGetizer" PackTransitively="false" />
198+
<PackageReference Update="NuGetizer" PackTransitively="false" />
199199
</ItemGroup>
200200

201201
<Target Name="_SetDefaultPackageReferencePack" Condition="'$(PackFolder)' == 'build' or '$(PackFolder)' == 'buildTransitive'"

src/NuGetizer.Tasks/NuGetizer.Shared.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Copyright (c) .NET Foundation. All rights reserved.
2020
<!-- Adds CodeAnalysis props and items needed for diagnostics -->
2121
<Import Project="NuGetizer.CodeAnalysis.targets" />
2222

23+
<ItemGroup>
24+
<!-- NuGetizer should *always* be a private asset. This avoids SL checks on P2P scenarios. -->
25+
<PackageReference Update="NuGetizer" PrivateAssets="all" />
26+
</ItemGroup>
27+
2328
<PropertyGroup>
2429
<!-- Whether to infer package contents -->
2530
<EnablePackInference Condition="'$(EnablePackInference)' == ''">true</EnablePackInference>

0 commit comments

Comments
 (0)