0.8.0 · Preview

Getting started

Add Avro Source Generator to your existing .NET project, include a schema, and use its generated model. Run the commands below from the directory containing your .csproj.

1. Check your tools

Use .NET SDK 10.0.100 or later. Visual Studio users should use Visual Studio 2026 18.0 or later with .NET 10 support.

dotnet --version

The SDK runs the generator during compilation. The SDK requirement is separate from your application’s target framework; the examples here use .NET 10. Keep generated language features and runtime dependencies compatible with your application’s target.

2. Install the packages

This example uses Apache.Avro:

dotnet add package AvroSourceGenerator --version 0.8.0-preview.2.main.11
dotnet add package Apache.Avro --version 1.12.2

If your project already uses Chr.Avro, review migration guidance before upgrading to 0.8.0.

Update the generator package reference created by installation with PrivateAssets and ExcludeAssets, and add the AdditionalFiles entry. Keep a single reference to each package:

<ItemGroup>
  <PackageReference Include="AvroSourceGenerator" Version="0.8.0-preview.2.main.11"
                    PrivateAssets="all" ExcludeAssets="runtime" />
  <PackageReference Include="Apache.Avro" Version="1.12.2" />
  <AdditionalFiles Include="schemas/*.avsc" />
</ItemGroup>

PrivateAssets keeps the generator out of your package’s public dependencies. ExcludeAssets prevents it from becoming a runtime reference. AdditionalFiles selects the schemas to compile.

3. Add a schema

Create a schemas directory in your project and save this as schemas/user.avsc:

{
  "type": "record",
  "name": "User",
  "namespace": "example",
  "fields": [
    { "name": "Name", "type": "string" },
    { "name": "Email", "type": ["null", "string"], "default": null }
  ]
}

The namespace is example, the generated type is User, and the properties are Name and Email.

4. Use the generated model

Build your application:

dotnet build

Use the generated type wherever your application needs it:

using example;

var user = new User
{
    Name = "Ada",
    Email = "ada@example.com",
};

Console.WriteLine($"{user.Name} <{user.Email}>");

For example, in a console application this prints Ada <ada@example.com>. You do not create User.cs yourself or run an extra generation command.

What next?