AvroSharp.Generators
1.0.0-rc.1
See the version list below for details.
dotnet add package AvroSharp.Generators --version 1.0.0-rc.1
NuGet\Install-Package AvroSharp.Generators -Version 1.0.0-rc.1
<PackageReference Include="AvroSharp.Generators" Version="1.0.0-rc.1" />
<PackageVersion Include="AvroSharp.Generators" Version="1.0.0-rc.1" />
<PackageReference Include="AvroSharp.Generators" />
paket add AvroSharp.Generators --version 1.0.0-rc.1
#r "nuget: AvroSharp.Generators, 1.0.0-rc.1"
#:package AvroSharp.Generators@1.0.0-rc.1
#addin nuget:?package=AvroSharp.Generators&version=1.0.0-rc.1&prerelease
#tool nuget:?package=AvroSharp.Generators&version=1.0.0-rc.1&prerelease
AvroSharp.Generators
A C# source generator for AvroSharp: it turns Avro schema files (.avsc) into C# types with serializers, and writes the schemas and serializers of your own C# types marked [AvroSerializable]. The generated code uses no reflection, so it works with Native AOT and trimming.
Status: a release candidate for 1.0.0. From 1.0, it follows semantic versioning: code generated by a version keeps compiling against later
AvroSharpruntimes of the same major version.
Code generation guide: every option, the type mapping, diagnostics, and moving from avrogen. Also: the avrosharp tool, documentation.
Usage
Reference the package and pass your schema files to the compiler as AdditionalFiles:
<ItemGroup>
<PackageReference Include="AvroSharp.Generators" Version="..." />
<AdditionalFiles Include="Schemas\*.avsc" />
</ItemGroup>
The GeneratorPackage sample is a complete project. The package brings in the AvroSharp runtime package. Each named type becomes a C# type: a record becomes a partial class, an enum a C# enum, and a fixed type a class that wraps exactly its number of bytes. Records implement the interfaces in AvroSharp.Serialization, such as IAvroSpecificRecord, and get serializers that call AvroWriter/AvroReader directly:
byte[] bytes = order.ToAvroBytes();
var copy = shop.Order.FromAvroBytes(bytes);
var upgraded = shop.Order.FromAvroBytes(oldBytes, writerSchema); // schema evolution
Options (MSBuild properties)
| Property | Values | Effect |
|---|---|---|
AvroSharpNamespace |
a C# namespace | The namespace of types without an Avro namespace |
AvroSharpNamespaceMap |
avro.ns:CSharp.Ns, separated by ; or , |
Maps Avro namespaces (and those under them) to C# namespaces, as avrogen's --namespace does |
AvroSharpPropertyNames |
avro, pascal |
avro keeps the Avro field names, as Apache's avrogen does; pascal converts them to PascalCase. Defaults to PascalCase, or to the Avro names with AvroSharpApacheCompatible |
AvroSharpLogicalTypes |
native, raw |
raw keeps logical types as their underlying types instead of DateOnly, Guid, decimal, … |
AvroSharpApacheCompatible |
true, false |
With true, generated types also implement Apache.Avro's ISpecificRecord and have avrogen's _SCHEMA and instance Schema; AvroSharp's schema is then AvroSharpSchema (requires a reference to Apache.Avro) |
Values are case-insensitive. An unrecognized value is warning AVROGEN006, and the default is used.
Requirements
The generator needs the .NET 10 SDK or Visual Studio 2026, because it runs AvroSharp inside the compiler (see #20). The generated code works on every target AvroSharp supports: .NET 8, 9 and 10, .NET Standard 2.0 and 2.1, and .NET Framework.
See the code generation guide for unions, logical types and the Apache.Avro compatibility mode.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- AvroSharp (>= 1.0.0-rc.1)
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 | 97 | 10/3/2026 |
| 1.0.0-rc.1 | 80 | 10/1/2026 |
| 0.2.0 | 579 | 9/29/2026 |
| 0.1.1 | 90 | 9/28/2026 |
| 0.1.0 | 90 | 9/28/2026 |