Cranks.Targets.AnalyzerReference
1.1.0
dotnet add package Cranks.Targets.AnalyzerReference --version 1.1.0
NuGet\Install-Package Cranks.Targets.AnalyzerReference -Version 1.1.0
<PackageReference Include="Cranks.Targets.AnalyzerReference" Version="1.1.0" />
paket add Cranks.Targets.AnalyzerReference --version 1.1.0
#r "nuget: Cranks.Targets.AnalyzerReference, 1.1.0"
// Install Cranks.Targets.AnalyzerReference as a Cake Addin #addin nuget:?package=Cranks.Targets.AnalyzerReference&version=1.1.0 // Install Cranks.Targets.AnalyzerReference as a Cake Tool #tool nuget:?package=Cranks.Targets.AnalyzerReference&version=1.1.0
This repository contains different projects which package usefule build targets to simplify certain tasks in your own projects. Right now it contains two projects simplyfying the creation and packaging process of analyzers and source generators. Theses packages never contain any source code and only enhance your existing build
Packages for Analyzer Support
Creating a good analyzer is hard enough. Delivering it to your end users is seemingly even harder. After countless hours of trial and error, I took inspiration in how Microsoft themselves ship their analyzers, by looking specifically at the repository for System.Text.Json. I have extracted the resulting targets into these projects to help other developers struggling with the same issues.
Targets in the packages below are either 1:1 copies from the dotnet/runtime repository, or heavily inspired by it. I merely extracted and packaged these targets for simplified use.
Packages
Cranks.Targets.Analyzer
Add this package to your analyzer projects.
The package adds a new MS Build target to your project called GetAnalyzerPackFiles
. When this target is called it returns a list of all the files which have to be packed into the analyzer folder of your libraries nuget package.
Cranks.Targets.AnalyzerReference
This package server to purposes:
- You want to ship a library directly with some analyzers
- You want to include an analyzer as a project reference
The package create a new reference Type
<AnalyzerReference>
with two attributes: - Pack includes the analyzer in the generated package
- ReferenceAnalyzer references the the analyer project and activates in your project
E.g. to ship a analyzer project directly with your library, add this to any <PropertyGroup>
in your project:
<AnalyzerReference Include="path\to\your\analyzer\project.csproj" Pack="true" ReferenceAnalyzer="false" />
MS Build Variables
The added targets make use of certain variables. These are not required to set, but should be used anyway:
AnalyzerLanguage
defines the language of your analyzer, and hence in which folder it gets added in the nuget package, e.g.cs
. Keep empty if your analyzer is language agnostic.AnalyzerRoslynVersion
The Roslyn version the package targets. This defines the apis you can use in your project and depends on the minimum visual studio version you want to targetRoslynApiVersion
The api version you can use in your analyzer. The<PackageReference>
of theMicrosoft.CodeAnalysis.CSharp.Workspaces
(or other languages you might want to be using) package should map to the value you enter here.
The AnalyzerRoslynVersion
and RoslynApiVersion
values depend on which version of visual studio you want to target and should always target the same version
To find which versions of VS correspond to which Roslyn version, take a look at .NET compiler platform package version reference.
Major.Minor.Patch
defines the RoslynApiVersion, whereas Major.Minor
restricts the AnalyzerRoslynVersion you want to target.
As an example, when you want to create a source generator for C#, targeting at least Visual Studio 2022 RTM (17.0), add this to your project files:
<PropertyGroup>
<AnalyzerLanguage>cs</AnalyzerLanguage>
<AnalyzerRoslynVersion>4.0</AnalyzerRoslynVersion>
<RoslynApiVersion>4.0.1</RoslynApiVersion>
</PropertyGroup>
The PackageReference to Microsoft.CodeAnalysis.*
projects, specifically the Microsoft.CodeAnalysis.CSharp.Workspaces
or the Microsoft.CodeAnalysis.VisualBasic.Workspaces
packages, should always match the value in <RoslynApiVersion>
It's therefore best, to reference these projects using
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="[$(RoslynApiVersion)]" PrivateAssets="all" />
</ItemGroup>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Cranks.Targets.AnalyzerReference:
Package | Downloads |
---|---|
Cranks.SeedWork.Domain
This package can act as a basis for the domain layer of your DDD application. It provides Analyzers ensuring correctness and source generation to reduce the amount of Boilerplate code you have to write. Still a very early version, it currently only supports Value Objects and Smart Enums. |
GitHub repositories
This package is not used by any popular GitHub repositories.