DragoAnt.Roslyn.Shared.Sources 1.0.0

dotnet add package DragoAnt.Roslyn.Shared.Sources --version 1.0.0
                    
NuGet\Install-Package DragoAnt.Roslyn.Shared.Sources -Version 1.0.0
                    
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="DragoAnt.Roslyn.Shared.Sources" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DragoAnt.Roslyn.Shared.Sources" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DragoAnt.Roslyn.Shared.Sources">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 DragoAnt.Roslyn.Shared.Sources --version 1.0.0
                    
#r "nuget: DragoAnt.Roslyn.Shared.Sources, 1.0.0"
                    
#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 DragoAnt.Roslyn.Shared.Sources@1.0.0
                    
#: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=DragoAnt.Roslyn.Shared.Sources&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DragoAnt.Roslyn.Shared.Sources&version=1.0.0
                    
Install as a Cake Tool

DragoAnt.Roslyn.Shared.Sources

Source-only helpers for Roslyn analyzers, source generators and code fixes: each component compiles its own internal copy, so no helper assembly has to load next to it and two packages built against different helper versions never collide.

Overview

DragoAnt.Roslyn.Shared.Sources is a development dependency with no lib/ folder. Its build/ targets add .cs files to the referencing project, which compiles them as internal types in the DragoAnt.Roslyn.Shared namespace. They show up in Solution Explorer under .da.shared/<Part>/.

Release notes · Issues

Key features

  • Parts per role — Common always, Generators for a source generator, CodeFixes for a code fix; one property, DragoAntRoslynSharedParts, picks them (consuming).
  • Nothing to load at run time — the helpers are compiled into each analyzer, generator and code fix, so the compiler never unifies two helper versions across packages (why sources).
  • Nothing reaches your users — the package is a private build-time reference: the analyzer package declares no dependency on it, and the projects that use the analyzer never restore it.
  • Your rules stay quiet — every file is marked <auto-generated/>, so your own code-style and quality analyzers skip code you cannot edit, while nullable checks stay on and the banned-API rules for analyzers still run.
  • Roslyn 5.0 and netstandard2.0 — the floor of the .NET 10 SDK compiler.

What is in 1.0

Part Type What it does
Common SyntaxHelpers the parameter a literal is passed to (call, constructor, positional, name: and params attribute arguments), compile-time constant strings, attributes by symbol or by metadata name
Common LocationHelpers a location inside a string literal's value; a location with line and column in an AdditionalText
Common DiagnosticHelpers diagnostics with an optional location; a guard that turns an exception in a callback into a diagnostic instead of AD0001
Generators EquatableArray<T> an array compared by its items, for incremental-generator models that cache
CodeFixes LiteralRewriter replaces a string literal in a document, keeping its trivia

Install

dotnet add package DragoAnt.Roslyn.Shared.Sources

Add it to the analyzer, generator or code-fix project, keep PrivateAssets="all" on the reference, and name the parts with DragoAntRoslynSharedParts (consuming).

Quick start

An analyzer that flags a space in any string passed to a parameter named path, at the column of the space:

using System.Collections.Immutable;
using DragoAnt.Roslyn.Shared;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class PathAnalyzer : DiagnosticAnalyzer
{
    private static readonly DiagnosticDescriptor Rule = new("CTS001", "Space in path", "Path '{0}' contains a space", "Usage", DiagnosticSeverity.Warning, true);

    public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [Rule];

    public override void Initialize(AnalysisContext context)
    {
        context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
        context.EnableConcurrentExecution();
        context.RegisterSyntaxNodeAction(c =>
        {
            var literal = (LiteralExpressionSyntax)c.Node;
            var space = literal.Token.ValueText.IndexOf(' ');
            if (space >= 0 && SyntaxHelpers.GetTargetParameter(c.SemanticModel, literal)?.Name == "path")
            {
                c.ReportDiagnostic(DiagnosticHelpers.Create(Rule, LocationHelpers.InStringLiteral(literal, space, 1), literal.Token.ValueText));
            }
        }, SyntaxKind.StringLiteralExpression);
    }
}

Licensed under the MIT licence.

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
1.0.0 157 10/6/2026
1.0.0-beta.1 125 10/6/2026