Skip to content

Commit

Permalink
Minimal docs on consuming
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Jun 7, 2024
1 parent 7cda4a1 commit 827a1d1
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/SponsorLink/readme.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
# .NET Sample
# SponsorLink .NET Analyzer

This sample contains an absolute minimal package that can be built and published to NuGet.org,
which contains just an analyzer assembly that consumes the SponsorLink package for nuget authors.
This is one opinionated implementation of [SponsorLink](https://devlooped.com/SponsorLink)
for .NET projects leveraging Roslyn analyzers.

It can be installed to a project by running the following dotnet command from the target
project directory:
It is intended for use by [devlooped](https://github.com/devlooped) projects, but can be
used as a template for other sponsorables as well. Supporting arbitrary sponsoring scenarios
is out of scope though, since we just use GitHub sponsors for now.

```
dotnet add package SponsorableLib --version 42.42.42-main.* -s https://pkg.kzu.io/index.json
```
## Usage

A project initializing from this template repo via [dotnet-file](https://github.com/devlooped/dotnet-file)
will have all the sources cloned under `src\SponsorLink`.

This will run the SponsorLink check with `https://github.com/sponsors/devlooped` for your
locally configured git email on IDE/Editor full builds.
Including the analyzer and targets in a project involves two steps.

The sample contains two analyzers, one with simple SponsorLink settings and an advanced one,
so you will get both running the sample check.
1. Create an analyzer project and add the following property:

The Analyzer folder contains the analyzer project, and the Tests project is set up to consume
it and allow for easy debugging by just running the Analyzer as the startup project from
Visual Studio (for example).
```xml
<PropertyGroup>
...
<CustomAfterMicrosoftCSharpTargets>$(MSBuildThisFileDirectory)..\SponsorLink\SponsorLink.targets</CustomAfterMicrosoftCSharpTargets>
</PropertyGroup>
```

2. Add a `buildTransitive\[PackageId].targets` file with the following import:

> NOTE: after initial restore, it might be necessary to restart the IDE for the analyzer
> assemblies to be properly resolved and loaded for debugging.
```xml
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Devlooped.Sponsors.targets"/>
</Project>
```

As long as NuGetizer is used, the right packaging will be done automatically.

0 comments on commit 827a1d1

Please sign in to comment.