Collection of Roslyn analyzers to improve code quality and avoid specific bugs.
- Documentation website: https://stackworx-dotnet.github.io/Stackworx.Analyzers/
- Package README (and full documentation):
docs/README.md
dotnet add package Stackworx.Analyzers<ItemGroup>
<PackageReference Include="Stackworx.Analyzers" Version="*" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>To try a local build of the analyzer in another solution before publishing, pack it into a local NuGet package and consume it from a private feed.
Pack the Stackworx.Analyzers.Package project into a .nupkg. Override the version so it sorts
above the published one and is easy to spot:
dotnet pack Stackworx.Analyzers.Package/Stackworx.Analyzers.Package.csproj -c Release -o ./local-nuget -p:Version=0.0.1-local.1Pack this project, not Stackworx.Analyzers — it's the one that bundles both the analyzer and the
code-fix assemblies (Stackworx.Analyzers.dll + Stackworx.Analyzers.Fixes.dll) into
analyzers/dotnet/cs. Packing Stackworx.Analyzers directly ships only the analyzer, so diagnostics
appear but the code fixes don't. This is the same project the publish workflow packs, so the resulting
package behaves exactly like the one on NuGet.org.
In the consuming project (or globally), register the output folder as a package source. Either add a
nuget.config next to the consuming solution:
<configuration>
<packageSources>
<add key="stackworx-local" value="/absolute/path/to/Stackworx.Analyzers/local-nuget" />
</packageSources>
</configuration>…or add it from the CLI:
dotnet nuget add source /absolute/path/to/Stackworx.Analyzers/local-nuget --name stackworx-local<ItemGroup>
<PackageReference Include="Stackworx.Analyzers" Version="0.0.1-local.1" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>NuGet caches packages by version. When iterating, bump the version on each
pack(e.g.-local.2,-local.3) — reusing a version means the old cached copy is used. If you must reuse a version, clear the cache first withdotnet nuget locals global-packages --clear.
If the project under test lives in the same solution (or you can reference the source directly), skip
packing entirely and reference the analyzer project — this is how
Stackworx.Analyzers.Sample consumes it:
<ItemGroup>
<PackageReference Include="Stackworx.Analyzers" PrivateAssets="all" />
</ItemGroup>After changing analyzer code, rebuild and restart the IDE's language server (or reload the window) so it picks up the new analyzer assembly.