CSharpAuthor 2.0.0-preview1000
See the version list below for details.
dotnet add package CSharpAuthor --version 2.0.0-preview1000
NuGet\Install-Package CSharpAuthor -Version 2.0.0-preview1000
<PackageReference Include="CSharpAuthor" Version="2.0.0-preview1000" />
<PackageVersion Include="CSharpAuthor" Version="2.0.0-preview1000" />
<PackageReference Include="CSharpAuthor" />
paket add CSharpAuthor --version 2.0.0-preview1000
#r "nuget: CSharpAuthor, 2.0.0-preview1000"
#:package CSharpAuthor@2.0.0-preview1000
#addin nuget:?package=CSharpAuthor&version=2.0.0-preview1000&prerelease
#tool nuget:?package=CSharpAuthor&version=2.0.0-preview1000&prerelease
CSharpAuthor
Programmatically generate C# source. Built for Roslyn source generators, where it is about
25× faster than SyntaxFactory + NormalizeWhitespace — 0.019 ms against 0.489 ms per file,
measured on the same machine in the same run.
You build a tree of definitions; it emits formatted C#. Types stay unrendered until the whole file is known, so namespaces are derived from what you actually wrote rather than declared on the side.
var file = new CSharpFileDefinition("TestNamespace");
var classDefinition = file.AddClass("TestClass");
var method = classDefinition.AddMethod("SomeMethod");
classDefinition.AddUsingNamespace("SomeNamespace");
var outputContext = new OutputContext();
file.WriteOutput(outputContext);
var outputString = outputContext.Output();
using SomeNamespace;
namespace TestNamespace
{
public class TestClass
{
public void SomeMethod()
{
}
}
}
Install
dotnet add package CSharpAuthor
CSharpAuthor ships as source, compiled into your project, so a source generator can use it
without taking on a dependency it would then have to redistribute. Set
PackageCSharpAuthorIncludeSource=true in a generator project.
An optional Roslyn bridge — ITypeSymbol → ITypeDefinition, and attribute reading — ships in the
same package behind PackageCSharpAuthorIncludeRoslyn=true. Your generator already references
Roslyn, so it costs nothing extra.
Why the type model matters
ITypeDefinition is not a string. It stays unrendered until serialization, which is what lets one
option flip an entire file between short names and global::, resolve same-name collisions with an
alias, and make a missing using structurally impossible.
var options = new OutputContextOptions { TypeOutputMode = TypeOutputMode.Global };
Global qualifies every reference and emits no derived usings — the recommended default for a
generator, and the faster path. ShortName gives you shorter names, derived using directives and
automatic collision aliasing.
Targeting a language version
The tree is version-agnostic; the writer decides how to render it. An EmitProfile says what the
target may use, and features downlevel where an equivalent exists — a collection expression becomes
new[] { … } below C# 12, silently and correctly. Where no equivalent exists, you get a
diagnostic rather than wrong output.
Documentation
- Getting started and guides
- Migrating from 1.x
- AGENTS.md — conventions, invariants and traps, for humans and AI agents working on the library itself
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- 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 |
|---|---|---|
| 2.0.0 | 1,720 | 9/6/2026 |
| 2.0.0-preview1005 | 2,123 | 8/28/2026 |
| 2.0.0-preview1004 | 171 | 8/22/2026 |
| 2.0.0-preview1003 | 131 | 8/22/2026 |
| 2.0.0-preview1002 | 115 | 8/21/2026 |
| 2.0.0-preview1001 | 118 | 8/21/2026 |
| 2.0.0-preview1000 | 114 | 8/21/2026 |
| 1.2.0 | 313 | 8/21/2026 |
| 1.1.1010 | 478 | 8/14/2026 |
| 1.1.1009 | 157 | 8/13/2026 |
| 1.1.1008 | 135 | 8/13/2026 |
| 1.1.1007 | 267 | 8/8/2026 |
| 1.1.1006 | 874 | 4/27/2025 |
| 1.1.1005 | 258 | 4/26/2025 |
| 1.1.1004 | 292 | 4/14/2025 |
| 1.1.1003 | 304 | 4/13/2025 |
| 1.1.1002 | 201 | 4/12/2025 |
| 1.1.1001 | 310 | 3/19/2025 |
| 1.0.9 | 215 | 3/14/2025 |
| 1.0.8 | 240 | 3/13/2025 |