CustomRoslynAnalyzer 0.1.2

dotnet add package CustomRoslynAnalyzer --version 0.1.2
                    
NuGet\Install-Package CustomRoslynAnalyzer -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CustomRoslynAnalyzer" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CustomRoslynAnalyzer" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="CustomRoslynAnalyzer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CustomRoslynAnalyzer --version 0.1.2
                    
#r "nuget: CustomRoslynAnalyzer, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CustomRoslynAnalyzer@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CustomRoslynAnalyzer&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=CustomRoslynAnalyzer&version=0.1.2
                    
Install as a Cake Tool

Roslyn Custom Analyzer package

CI Status Release Status NuGet

CustomRoslynAnalyzer is a .NET Standard 2.0 analyzer library that ships as a NuGet package (the workflow already packs/publishes it) and exposes the following diagnostics to consumers:

ID Category Description
CR0001 Usage Flags Console.WriteLine calls so you can enforce a logging abstraction instead of writing directly to standard output.
CR0002 Naming Requires public async methods to end with Async, making their asynchronous nature explicit.
CR0003 Usage Warns whenever traditional loops or lambda-based iterations invoke services deeper in Infrastructure namespaces, helping avoid repeated expensive work.
CR0004 Usage Prevents services or repositories (and methods that depend on them) from being used inside foreach loops or lambda iterations.

Since these rules run inside the analyzer, any consuming project that references the NuGet package (or project reference with OutputItemType="Analyzer") will surface CR0001–CR0004 as compiler warnings.

Violations in SampleApp

SampleApp/Program.cs intentionally demonstrates the diagnostics emitted by the analyzer. In the loop below, the analyzer flags the Console.WriteLine call (CR0001) and the repetitive call to a service defined in SampleApp.Infrastructure (CR0003):

for (var i = 0; i < count; i++)
{
	Trace.WriteLine($"Iteration {i + 1}/{count}");
	await worker.FetchTelemetryAsync(); // violates CR0003 because `TelemetryApiClient` lives under SampleApp.Infrastructure
	_ = await worker.Compute(); // violates CR0002 because Compute() do not end with `Async` 
}

Console.WriteLine($"Telemetry fetched from {snapshot.Source}."); // violates CR0001

The analyzer also warns if any public async methods (such as BackgroundWorker.Compute) do not end with Async, which is how CR0002 stays enforced.

Next steps

  • Add more DiagnosticAnalyzer implementations (and accompanying code fixes, if desired) under Rules/.
  • Keep AnalyzerReleases.Shipped.md and .Unshipped.md in sync with released rule IDs so versioned release notes stay accurate.
  • Add analyzer unit tests using Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit when you need automated verification of diagnostics.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 5,917 12/5/2025
0.1.1 247 12/4/2025