AvroSharp.Generators
0.1.1
dotnet add package AvroSharp.Generators --version 0.1.1
NuGet\Install-Package AvroSharp.Generators -Version 0.1.1
<PackageReference Include="AvroSharp.Generators" Version="0.1.1" />
<PackageVersion Include="AvroSharp.Generators" Version="0.1.1" />
<PackageReference Include="AvroSharp.Generators" />
paket add AvroSharp.Generators --version 0.1.1
#r "nuget: AvroSharp.Generators, 0.1.1"
#:package AvroSharp.Generators@0.1.1
#addin nuget:?package=AvroSharp.Generators&version=0.1.1
#tool nuget:?package=AvroSharp.Generators&version=0.1.1
AvroSharp.Generators
A C# source generator that turns Avro schema files (.avsc) into C# types with serializers for AvroSharp. The generated code uses no reflection, so it works with Native AOT and trimming.
Status: early development, not yet released.
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 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 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 |
AvroSharpPropertyNames |
avro |
Keeps the Avro field names, as Apache's avrogen does, instead of PascalCase |
AvroSharpLogicalTypes |
raw |
Keeps logical types as their underlying types instead of DateOnly, Guid, decimal, … |
AvroSharpApacheCompatible |
true |
Generated types also implement Apache.Avro's ISpecificRecord (requires a reference to Apache.Avro) |
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 repository README for unions, logical types and the Apache.Avro compatibility mode.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- AvroSharp (>= 0.1.1)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.12)
- System.Memory (>= 4.6.3)
- System.Text.Json (>= 10.0.12)
- System.Threading.Channels (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.