Skip to content

Commit 36042e0

Browse files
committed
Make NuGetizer targets buildTransitive to fix SponsorLink
For development-dependency packages, no assets flow across project references, including build targets and package dependencies. This is problematic for SponsorLink since it needs targets to properly surface build properties to the analyzer that performs the checks. By making NuGetizer build targets transitive, we fix the project to project (P2P) scenario where one project installs NuGetizer and referencing projects start failing the SponsorLink check because the SL targets are missing. (since the package dependency on SL isn't surfaced in that case). By also including the SL targets in our package and conditionally importing them if they haven't already been imported, we further remove the changes that the missing dependency causes failures. This might not be the optimal way to solve this, but it's the only one that works consistently. This obviously causes P2P references to a project consuming NuGetizer to *also* become nugetized themselves. This should be a minor issue, however.
1 parent a77c3e1 commit 36042e0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/CodeAnalysis/CodeAnalysis.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.1.3" PrivateAssets="all" />
1515
<PackageReference Include="ThisAssembly.Strings" Version="1.1.3" PrivateAssets="all" />
1616
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
17-
<PackageReference Include="Devlooped.SponsorLink" Version="42.42.221-main" PrivateAssets="all" />
17+
<PackageReference Include="Devlooped.SponsorLink" Version="0.10.0" GeneratePathProperty="true" />
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<None Update="NuGetizer.CodeAnalysis.targets" PackFolder="build" CopyToOutputDirectory="PreserveNewest" />
21+
<None Update="NuGetizer.CodeAnalysis.targets" PackFolder="buildTransitive" CopyToOutputDirectory="PreserveNewest" />
22+
<None Include="$(PkgDevlooped_SponsorLink)\buildTransitive\Devlooped.SponsorLink.targets"
23+
PackFolder="buildTransitive"
24+
CopyToOutputDirectory="PreserveNewest" />
2225
</ItemGroup>
2326

2427
</Project>

src/CodeAnalysis/NuGetizer.CodeAnalysis.targets

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
<CompilerVisibleProperty Include="Authors" />
2020
<CompilerVisibleProperty Include="AssemblyName" />
21-
22-
<SponsorablePackageId Include="NuGetizer" />
2321
</ItemGroup>
2422

2523
<Target Name="_AddDescription" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun">
@@ -29,4 +27,13 @@
2927
</ItemGroup>
3028
</Target>
3129

30+
<ItemGroup Label="SponsorLink">
31+
<SponsorablePackageId Include="NuGetizer" />
32+
</ItemGroup>
33+
34+
<!-- This ensures devlooped targets are imported transitively even if we are a dev dependency
35+
and therefore don't propagate the SL dependency, which would otherwise cause a build error
36+
due to analyzers being forcedly transitive even if the reference is private assets/dev dep.
37+
-->
38+
<Import Project="Devlooped.SponsorLink.targets" Condition="$(SponsorLinkImported) != true"/>
3239
</Project>

src/NuGetizer.Tasks/NuGetizer.Tasks.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Description>Simple, flexible and powerful NuGet packaging</Description>
2020

2121
<DevelopmentDependency>true</DevelopmentDependency>
22-
<PackFolder>build</PackFolder>
22+
<PackFolder>buildTransitive</PackFolder>
2323

2424
<PackOnBuild Condition="'$(PackOnBuild)' == '' And '$(Configuration)' == 'Release'">true</PackOnBuild>
2525
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">..\..\bin</PackageOutputPath>

0 commit comments

Comments
 (0)