Devlooped.SponsorLink 1.0.0
Integrate GitHub Sponsors into your libraries so that users can be properly linked to their sponsorship to unlock features or simply get the recognition they deserve for supporting your project.
SponsorLink for .NET allows you to integrate sponsorship checks in the build process itself, without affecting IDE/Editor performance or command line/CI builds. Learn more about SponsorLink for open source developers and the onboarding process.
NOTE: this package is intended for package authors. Downstream package consumers should get it transitively automatically to support the SponsorLink checks.
Usage
Add the following analyzer to an analyzer project you include in your package:
using Devlooped;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace SponsorableLib;
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
class SponsorLinker : SponsorLink
{
public SponsorLinker() : base("[SPONSORABLE]", "[PROJECT]")
{ }
}
Replace SPONSORABLE
with your sponsor account login and PROJECT
with a recognizable
name of your project or library (i.e. ThisAssembly
or Moq
). Optionally, use the
base constructor overload receiving a SponsorLinkSettings
which offers many options
to customize the behavior of the analyzer.
Make sure you have installed the GitHub SponsorLink Admin app and have followed the onboarding steps.
We recommend using NuGetizer for packing your libraries, which provides the easiest integration with SponsorLink too. Simply add a project reference from your main library to the analyzer project and all packaging should Just Work. An example analyzer project referenced by your main library is typically just:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackFolder>analyzers/dotnet</PackFolder>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGetizer" Version="0.9.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
<PackageReference Include="Devlooped.SponsorLink" Version="[VERSION]" />
</ItemGroup>
</Project>
To only run the SponsorLink check when a consumer directly references you package, include a
buildTransitive
targets file with your package that surfaces the relevant package id to the
analyzer:
<Project>
<ItemGroup>
<SponsorablePackageId Include="[YOUR_PACKAGE_ID]" />
</ItemGroup>
</Project>
Learn more about SponsorLink NuGet integration.
How it works
When you ship a new version of your library including the above analyzer, the first build in an IDE/editor session will result in one of these three messages:
User does not have the GitHub SponsorLink (user) app installed in his personal account. Warning SL02:
User installed the app, but is not sponsoring the sponsorable account. Warning SL03:
User installed the app and is sponsoring:
NOTE: you can provide your own actions for the above scenarios, or simply configure the default behavior by tweaking the min/max amount of random waits introduced during builds. By default, the waits will range from 0 to 4000ms. Use to relevant constructor overload in combination with
SponsorLinkSettings.Create()
factory method to access all configurable options.
The goal of SponsorLink is to help make your project more sustainable, support your ongoing development and ensure your customers can depend on it in the long run!
Learn more about SponsorLink NuGet integration, in particular the section on properly packing to workaround the issue of forced transitiveness of analyzers in the .NET SDK.
Sponsors
Showing the top 20 packages that depend on Devlooped.SponsorLink.
Packages | Downloads |
---|---|
Moq
Moq is the most popular and friendly mocking framework for .NET.
|
5 |
.NET Standard 2.0
- No dependencies.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 6 | 10/29/2024 |