Skip to main content
Any Framework

Source helpers for Roslyn analyzers and source generators

Published
Aug 19, 2026
2mo ago
Total Downloads
7.2K
7,214

Install

dotnet add package Meziantou.Framework.Roslyn --version 1.0.1

No framework information available.

README

Meziantou.Framework.Roslyn

Meziantou.Framework.Roslyn provides source helpers for Roslyn analyzers and source generators. The package does not ship a library assembly; helper code is compiled into the consuming project.

Usage

Install the package in an analyzer or source generator project that already references Roslyn packages:

<ItemGroup>
  <PackageReference Include="Meziantou.Framework.Roslyn" Version="x.y.z" PrivateAssets="all" />
  <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.6.0" PrivateAssets="all" />
</ItemGroup>

Then import the helper namespace:

using Meziantou.Framework.Roslyn;

Helpers

  • Compilation.GetBestTypeByMetadataName
  • Compilation.IsNet9OrGreater
  • ContextExtensions.ReportDiagnostic
  • DiagnosticReporter
  • IOperation.UnwrapImplicitConversions
  • LanguageVersionExtensions
  • LocalDataFlowAnalysis
  • LocationExtensions
  • MethodSymbolExtensions
  • NamespaceSymbolExtensions
  • SuppressorHelpers
  • SymbolAttributeExtensions
  • ISymbol.GetFirstSourceLocation
  • ISymbol.IsVisibleOutsideOfAssembly
  • ITypeSymbol.GetUnderlyingNullableTypeOrSelf

The package also defines Roslyn and C# feature constants before compilation based on the referenced Microsoft.CodeAnalysis.* package version, such as ROSLYN_4_8_OR_GREATER and CSHARP12_OR_GREATER.

Compiler warnings

The helper files suppress all compiler warnings so they don't pollute the consuming project's build. Define the MEZIANTOU_FRAMEWORK_ROSLYN_ENABLE_WARNINGS constant to report them:

<PropertyGroup>
  <DefineConstants>$(DefineConstants);MEZIANTOU_FRAMEWORK_ROSLYN_ENABLE_WARNINGS</DefineConstants>
</PropertyGroup>

Changes from Previous Version

No structural changes between v1.0.0 and v1.0.1.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.