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
<PackageReference Include="DragoAnt.Roslyn.Shared.Sources" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="DragoAnt.Roslyn.Shared.Sources" Version="1.0.0" />
<PackageReference Include="DragoAnt.Roslyn.Shared.Sources"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add DragoAnt.Roslyn.Shared.Sources --version 1.0.0
#r "nuget: DragoAnt.Roslyn.Shared.Sources, 1.0.0"
#:package DragoAnt.Roslyn.Shared.Sources@1.0.0
#addin nuget:?package=DragoAnt.Roslyn.Shared.Sources&version=1.0.0
#tool nuget:?package=DragoAnt.Roslyn.Shared.Sources&version=1.0.0
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>/.
Key features
- Parts per role —
Commonalways,Generatorsfor a source generator,CodeFixesfor 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.
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 |