![]() |
VOOZH | about |
dotnet add package ANcpLua.Roslyn.Utilities --version 2.2.27
NuGet\Install-Package ANcpLua.Roslyn.Utilities -Version 2.2.27
<PackageReference Include="ANcpLua.Roslyn.Utilities" Version="2.2.27" />
<PackageVersion Include="ANcpLua.Roslyn.Utilities" Version="2.2.27" />Directory.Packages.props
<PackageReference Include="ANcpLua.Roslyn.Utilities" />Project file
paket add ANcpLua.Roslyn.Utilities --version 2.2.27
#r "nuget: ANcpLua.Roslyn.Utilities, 2.2.27"
#:package ANcpLua.Roslyn.Utilities@2.2.27
#addin nuget:?package=ANcpLua.Roslyn.Utilities&version=2.2.27Install as a Cake Addin
#tool nuget:?package=ANcpLua.Roslyn.Utilities&version=2.2.27Install as a Cake Tool
A focused utility library for writing Roslyn source generators, analyzers, and code-fix providers. The shape is opinionated: the types here are the ones that make an incremental generator actually cache, a symbol comparison actually readable, and a code emission actually deterministic.
Agent test doubles, MAF conformance suites, and workflow fixtures live in the sibling ANcpLua.Agents package. This repo focuses on Roslyn/MSBuild/OTel-for-analyzer-authors.
The library is the author's own. Use it, improve it (the upstream is this repo), or propose switching directions — don't reinvent locally.
| Package | Target | What it's for |
|---|---|---|
ANcpLua.Roslyn.Utilities |
netstandard2.0 | Runtime + Roslyn utilities as a normal NuGet reference |
ANcpLua.Roslyn.Utilities.Sources |
source-only | Embeds the utilities as internal source into source generators (generators can't load NuGet DLLs at runtime) |
ANcpLua.Roslyn.Utilities.Polyfills |
source-only | init, required, Index/Range, nullable & trim attributes for netstandard2.0 |
ANcpLua.Roslyn.Utilities.Testing |
net10.0 | Generator/analyzer/codefix test infrastructure, MSBuild/NuGet integration tests, cross-framework web testing (xUnit/NUnit/TUnit/Bunit), OTel instrumentation helpers |
ANcpLua.Roslyn.Utilities.Testing.Aot |
netstandard2.0 | AOT/trim test attributes ([AotTest], [TrimTest], [AotSafe], [TrimSafe]), TrimAssert, FeatureSwitches, MSBuild orchestration for standalone AOT verification |
dotnet add package ANcpLua.Roslyn.Utilities.Sources
A canonical incremental generator is ~25 lines when the utilities do their job — see src/ANcpLua.AotReflection/AotReflectionGenerator.cs in this repo for the reference shape:
[Generator]
public sealed class MyGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var flows = context.SyntaxProvider.ForAttributeWithMetadataName(
"MyNamespace.TracedAttribute",
static (node, _) => node is ClassDeclarationSyntax,
static (ctx, ct) => TypeExtractor.Extract(ctx, ct));
var types = flows.ReportAndStop(context);
var files = types
.Select(static (m, _) => OutputGenerator.Generate(m))
.CollectAsEquatableArray();
files.AddSources(context);
}
}
What the library provides at each step:
ForAttributeWithMetadataName — filter syntax before expensive semantic work (Roslyn built-in; the library wraps for ergonomics)DiagnosticFlow<T> — railway-oriented pipeline carrying value + accumulated diagnostics, value-equatable for incremental cachingReportAndStop — drain the flow into ReportDiagnostic and yield valuesCollectAsEquatableArray / ToEquatableArray / ToEquatableArrayOrDefault — value-equatable collections so the generator cache actually hitsAddSources — emit FileWithName records without boilerplateMatch.Type() / Match.Method() — fluent symbol matching, no string comparisonsIndentedStringBuilder — BeginBlock()/EndBlock() scopes, no hardcoded indentation stringsGeneratedCodeHelpers — <auto-generated/> headers, #nullable enable, pragma helpersAgent test doubles (FakeChatClient, FakeReplayAgent, ActivityCollector), the provider-agnostic MAF conformance suite (RunTests, RunStreamingTests, ChatClientAgentRunTests, StructuredOutputRunTests), reference fixtures for OpenAI / Azure / Anthropic / Ollama / Gemini / OpenRouter, and the WorkflowFixture<TInput> harness ship in the sibling ANcpLua.Agents package.
DiagnosticFlow<T> + DiagnosticFlowReportingExtensions — railway-oriented flow with value + accumulated DiagnosticInfoIncrementalValuesProviderExtensions — ReportAndStop, CollectAsEquatableArray, AddSources, and other pipeline verbsSyntaxValueProviderExtensions — ergonomic ForAttributeWithMetadataName wrappersSourceProductionContextExtensions — context helpersEquatableArray<T> + EquatableArrayExtensions (.ToEquatableArray, .ToEquatableArrayOrDefault, .AsEquatableArray) — value equality so the cache actually hitsFileWithName — record for emitted-file payloadDiagnosticInfo + LocationInfo + EquatableMessageArgs — value-equatable diagnostic carriers; IsDefault/IsError predicates let pipeline code skip default sentinels at the boundary instead of NRE'ing inside RoslynResultWithDiagnostics<T> — result payload paired with diagnostics, with HasResult distinguishing a successful null from a no-result envelope. Pair with SelectAndCaptureExceptions (side-effect-free) or SelectAndReportExceptions (chains capture + register-source-output) on IncrementalValuesProviderExtensions.Match fluent DSL — Match.Type() / Match.Method() / Match.Property() / Match.Field() / Match.Parameter() with the per-kind matchers under Matching/ (MethodMatcher, TypeMatcher, etc.)Invoke / InvocationMatcher — invocation-shape matchingSymbolExtensions, TypeSymbolExtensions, MethodSymbolExtensions, NamespaceExtensions — IsEqualTo, Implements, InheritsFrom, IsOrImplements, GetMetadataName (overloaded for type and namespace symbols), and the usual suspects. Symbol identity beats ToDisplayString() for predicate hot paths — see IsSpanType/IsMemoryType/IsTaskType for the pattern.AttributeExtensions — GetAttribute, HasAttribute, TryGetAttribute with constructor-arg accessorsInvocationExtensions / OperationExtensions / OperationHelper — IInvocationOperation analysis helpersSemanticGuard<T> + SemanticGuard — chain semantic predicates with early-exitSemanticModelExtensions / CompilationExtensions / SyntaxExtensionsIndentedStringBuilder + IndentScope — BeginBlock()/EndBlock() scopes, no hardcoded indentationGeneratedCodeHelpers — <auto-generated/> header, nullable/pragma directivesValueStringBuilder — stack-allocated StringBuilder for hot pathsSyntaxBuilders (Analyzers/) — fluent builders for common code-fix patterns (ExtensionCall, StaticCall, NameOf)Reusable infrastructure for writing analyzers and code fixes — concrete rules (e.g. AL0126) intentionally ship in ANcpLua.Analyzers.
DiagnosticAnalyzerBase — convention base classDiagnosticCategories / DiagnosticSeverities — category/severity constantsDeprecatedOtelAttributes — 50+ attribute-name mappings synced to OTel GenAI semconv 1.40 (catches gen_ai.system and friends during analysis)IncrementalPipelineHelpers — pipeline wiring utilitiesMappingRegistry / TypeCache<TEnum> — cached lookups for analyzer hot pathsAsyncSequenceExtensions — LINQ-ish operators over IAsyncEnumerable<T>ParallelAsyncExtensions — SelectParallel (completion order) / SelectParallelOrdered (source order), channel-based fan-out with linked-CTS cancellation so a single selector exception cancels every sibling workerExpiringCache<TKey,TValue> — access-order LRU with single-flight factory invocation via Lazy<TValue?> (no thundering herd on concurrent misses for the same key)TimeConversions — OTel nanosecond helpersDictionaryExtensions — GetOrInsert(key, context, factory) (closure-free, hot-path), GetOrAdd(key) / GetOrAdd(key, factory) (ergonomic), MapIfAbsent(src, dst, transform) (cross-key copy for vendor-adapter telemetry mappers)EnumerableExtensions — dedup, partition, chunking, MinBy/MaxByListExtensions — in-place mutation helpersGuard — null / range / path / type guardsNullableExtensions — Map-style combinators for T?TryExtensions — TryParseX (every overload pinned to CultureInfo.InvariantCulture so a German dev's "1,5" doesn't silently parse as 1.5 in production), dictionary GetOrNull / GetOrDefault / GetOrElseSpanKind, SpanStatusCode — OTel enumsPagedResult<T> — standard paginated response shapeLanguage and API backports for netstandard2.0 consumers (via the separate .Polyfills package):
| Polyfill | Enables | Opt-out |
|---|---|---|
Index / Range |
array[^1], array[1..3] |
InjectIndexRangeOnLegacy=false |
IsExternalInit |
record types, init setters |
InjectIsExternalInitOnLegacy=false |
| Nullable attributes | [NotNull], [MaybeNull], [MemberNotNull], [NotNullWhen] |
InjectNullabilityAttributesOnLegacy=false |
| Trim/AOT attributes | [RequiresUnreferencedCode], [DynamicallyAccessedMembers] |
InjectTrimAttributesOnLegacy=false |
TimeProvider |
Testable time abstraction | InjectTimeProviderPolyfill=false |
Lock |
System.Threading.Lock |
InjectLockPolyfill=false |
required, params collections, CallerArgumentExpression, UnreachableException, StackTraceHidden, ExperimentalAttribute |
C# 11–13 language features on ns2.0 | per-feature MSBuild props |
Disable all at once: <InjectAllPolyfillsOnLegacy>false</InjectAllPolyfillsOnLegacy>
.TestingGenerator, analyzer, codefix, refactoring, MSBuild integration, and cross-framework web testing.
Test<TGenerator> (fluent entry), GeneratorTestHelper.RunGenerator<TGenerator>() (assertion-oriented one-liners), GeneratorCachingReport (compares two runs, detects cache hits), Compile / CompileResult (dynamic compilation with Shouldly-style assertions)AnalyzerTest<TAnalyzer>, CodeFixTest<TAnalyzer,TCodeFix>, CodeFixTestWithEditorConfig<TAnalyzer,TCodeFix>, RefactoringTest<TRefactoring>, SolutionRefactoringTest<TRefactoring>, LogAssertProjectBuilder, PackageProjectBuilder, PackageTestBase<TFixture> / NuGetPackageTestBase, NuGetPackageFixture, BuildResult + BuildResultAssertions, SarifFile parsers, DotNetSdkHelpers / NetSdkVersion, MSBuildConstantsIntegrationTestBase<TProgram>, KestrelTestBase<TProgram>WebTesting/NUnit/, WebTesting/TUnit/, WebTesting/Bunit/ — per-framework equivalentsFakeLoggerExtensions for structured log captureActivityInstrumentation, MetricsInstrumentation, LoggingConventions, LogEnricherInfrastructure, DataClassificationHelpers (PII/Secret redaction).Testing.AotSeparate package (netstandard2.0, zero runtime deps). Attributes + MSBuild props for verifying AOT/trim behavior.
[AotTest], [AotSafe], [AotUnsafe] — mark methods as AOT-verified or AOT-excluded[TrimTest], [TrimSafe], [TrimUnsafe] — same for IL trimming; TrimMode enum selects Partial / FullTrimAssert.TypePreserved(...) / TypeRemoved(...) — runtime assertions against the trimmed binaryFeatureSwitches — constants for common AOT feature switches (e.g. JsonReflection)AotRuntime — runtime AOT/trim detectionbuild/*.props + *.targets + ProjectTemplate.csproj.txt) ships inside the package itself; no external SDK dependencyThis repo also ships ANcpLua.Analyzers.AotReflection — an incremental source generator that replaces runtime typeof(T).GetProperties() with compile-time metadata, making types NativeAOT- and trim-safe. Mark a type [AotReflection] and a generated FooMetadata class appears with strongly-typed getter/setter/invoker delegates. Pair with ANcpLua.Roslyn.Utilities.Testing.Aot to verify the output survives PublishAot=true and PublishTrimmed=true.
EquatableArray<T> for generator caching, DiagnosticFlow<T> for pipeline error accumulation, IndentedStringBuilder for emission — the shape of an incremental generator the compiler cache actually likes.ValueStringBuilder for stack-allocated string building, Boxes for cached boxed primitives, closure-free GetOrInsert<TContext> for dictionary inserts.DeprecatedOtelAttributes catches gen_ai.system and 50+ other deprecated attribute names during analysis.GeneratorCachingReport over hand-rolled cache assertions. Test<TGenerator> fluent runner over hand-rolled CSharpGeneratorDriver plumbing. The shipped-internally ForbiddenTypeAnalyzer catches ISymbol/Compilation snuck into pipeline models. Agent-specific test doubles live in the sibling ANcpLua.Agents package..Sources package rewrites the utilities to internal via a pack-time PowerShell transform (Transform-Sources.ps1), because source generators can't load NuGet DLLs at runtime.ancplua.mintlify.app/utilities — full API reference with examples.
MIT © Alexander Nachtmann
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on ANcpLua.Roslyn.Utilities:
| Package | Downloads |
|---|---|
|
ANcpLua.Roslyn.Utilities.Testing
Fluent testing framework for Roslyn analyzers, code fixes, and incremental generators with caching validation, forbidden type detection, and comprehensive assertion support. |
|
|
ANcpLua.Agents
Consumer toolkit spine for Microsoft Agent Framework. Bundling facades plus governance primitives: call lineage, spawn tracker, budget enforcer, concurrency limiter, and governed AIFunction. |
|
|
ANcpLua.Agents.Testing
Test infrastructure for Microsoft Agent Framework. Fake agents, scripted chat clients, SSE parsing, mock HTTP handlers, and IChatClientAgentFixture reference implementations for OpenAI, Azure OpenAI, Anthropic, Ollama, Google Gemini, and OpenRouter. |
|
|
ANcpLua.Agents.Testing.Workflows
Test infrastructure for Microsoft Agent Framework Workflows. Fluent fixture base with assertion builders, an execution-environment parametric axis, and ANcpLua-authored facades over MAF Workflows internals (facade / decorator / railway / fluent / extension methods) — designed for expressiveness and loose coupling, not a 1:1 mirror of upstream. |
|
|
ANcpLua.Agents.Workflows
Workflow facades and execution helpers for Microsoft Agent Framework consumers. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.2.27 | 64 | 6/14/2026 |
| 2.2.26 | 724 | 5/29/2026 |
| 2.2.25 | 122 | 5/29/2026 |
| 2.2.24 | 1,863 | 5/28/2026 |
| 2.2.23 | 477 | 5/28/2026 |
| 2.2.22 | 396 | 5/23/2026 |
| 2.2.21 | 262 | 5/23/2026 |
| 2.2.20 | 116 | 5/23/2026 |
| 2.2.19 | 166 | 5/18/2026 |
| 2.2.18 | 135 | 5/18/2026 |
| 2.2.17 | 117 | 5/18/2026 |
| 2.2.16 | 118 | 5/16/2026 |
| 2.2.15 | 113 | 5/16/2026 |
| 2.2.14 | 119 | 5/16/2026 |
| 2.2.13 | 100 | 5/16/2026 |
| 2.2.12 | 382 | 5/11/2026 |
| 2.2.11 | 248 | 5/9/2026 |
| 2.2.10 | 164 | 5/8/2026 |
| 2.2.9 | 193 | 5/7/2026 |
| 2.2.8 | 112 | 5/7/2026 |