Skip to content

Commit 697e210

Browse files
committed
Fix overwriting of $(FundingPackageId) in targets
The existig Devlooped.Sponsors.targets had a bug in that it used the same property name the analyzer uses, for its temporary projection from @(FundingPackageId). This caused the property to overwritten, which manifested as soon as we bumped ThisAssembly.AssemblyInfo, which imports the buggy targets into the sample analyzer too now. By using `_FundingPackage` as the property name instead, analyzers leveraging ThisAssembly won't have an issue from now on, and more importantly: we remove the limitation that only non-SLv2 versions of ThisAssembly could be used previously (unless you implemented an unintuitive workaround like we do in this commit in the Analyzer.csproj via the @(FundingPackageId) item, which won't be necessary from now on (as soon as we can bump again ThisAssembly).
1 parent 0f551e3 commit 697e210

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

samples/dotnet/Analyzer/Analyzer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
<ItemGroup>
3131
<InternalsVisibleTo Include="Tests" />
32+
<!-- $(FundingPackageId) will suffice once ThisAssembly bumps to this fixed Devlooped.Sponsors.targets -->
33+
<FundingAnalyzerPackageId Include="SponsorableLib" />
3234
</ItemGroup>
3335

3436
<!-- To support tests, fake an extra sponsorable with the test key -->

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161

6262
<Target Name="SL_CollectSponsorableAnalyzer" Inputs="@(FundingPackageId)" Outputs="|%(FundingPackageId.Identity)|">
6363
<PropertyGroup>
64-
<FundingPackageId>%(FundingPackageId.Identity)</FundingPackageId>
64+
<_FundingPackageId>%(FundingPackageId.Identity)</_FundingPackageId>
6565
</PropertyGroup>
6666
<ItemGroup>
6767
<!--Used to determine installation time, for example, by looking up the analyzer assembly in additional files with:
6868
build_metadata.Analyzer.ItemType = Analyzer
6969
build_metadata.Analyzer.NuGetPackageId = [PackageId] -->
70-
<AdditionalFiles Include="@(Analyzer -> WithMetadataValue('NuGetPackageId', '$(FundingPackageId)'))" />
70+
<AdditionalFiles Include="@(Analyzer -> WithMetadataValue('NuGetPackageId', '$(_FundingPackageId)'))" />
7171
</ItemGroup>
7272
</Target>
7373

samples/dotnet/Tests/AnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public async Task WhenMultipleAnalyzers_ThenReportsOnce()
213213
.Where(x => x.Properties.TryGetValue(nameof(SponsorStatus), out var _));
214214

215215
Assert.NotEmpty(diagnostics);
216-
Assert.Single(diagnostics.Where(x => x.Properties.TryGetValue(nameof(SponsorStatus), out var value)));
216+
Assert.Single(diagnostics, x => x.Properties.TryGetValue(nameof(SponsorStatus), out var value));
217217
}
218218

219219
[Fact]

samples/dotnet/readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ Including the analyzer and targets in a project involves two steps.
3535
</Project>
3636
```
3737

38+
3. Set the package id(s) that will be checked for funding in the analyzer, such as:
39+
40+
```xml
41+
<PropertyGroup>
42+
<FundingPackageId>SponsorableLib;SponsorableLib.Core</FundingPackageId>
43+
</PropertyGroup>
44+
```
45+
46+
The default analyzer will report a diagnostic for sponsorship status only
47+
if the project being compiled as a direct package reference to one of the
48+
specified package ids.
49+
50+
This property defaults to `$(PackageId)` if present. Otherwise, it defaults
51+
to `$(FundingProduct)`, which in turn defaults to `$(Product)` if not provided.
52+
3853
As long as NuGetizer is used, the right packaging will be done automatically.

0 commit comments

Comments
 (0)