AvroGen.NET.Tool
0.5.47
dotnet tool install --global AvroGen.NET.Tool --version 0.5.47
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local AvroGen.NET.Tool --version 0.5.47
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=AvroGen.NET.Tool&version=0.5.47
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package AvroGen.NET.Tool --version 0.5.47
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AvroGen.NET
MSBuild-based tool for generating C# classes from Avro schemas stored in Schema Registry.
Features
- Automatic C# class generation from Avro schemas
- Integration with Confluent Schema Registry
- MSBuild integration for automatic code generation during build
- Command-line tool for manual code generation
- Support for all Avro data types
- Namespace customization
- Generated classes are compatible with Confluent.SchemaRegistry.Serdes.Avro
Installation
NuGet Package (MSBuild Integration)
dotnet add package AvroGen.NET
Command Line Tool
dotnet tool install -g AvroGen.NET.Tool
Usage
MSBuild Integration (Recommended)
Add the following to your project file:
<ItemGroup>
<AvroSchema Include=".">
<SchemaRegistryUrl>http://localhost:8081</SchemaRegistryUrl>
<Subject>your-schema-subject</Subject>
<Version>1</Version>
<OutputDirectory>$(MSBuildProjectDirectory)\Generated</OutputDirectory>
<Namespace>$(RootNamespace).Generated</Namespace>
</AvroSchema>
</ItemGroup>
The classes will be generated automatically during build. You can also generate them manually by running:
dotnet build
Command Line Tool
For one-time generation or when you need more control, you can use the command line tool:
# Generate from latest schema version
avrogennet --schema-registry-url http://localhost:8081 --subject user-value --output-directory ./Generated
# Generate from specific schema version
avrogennet --schema-registry-url http://localhost:8081 --subject user-value --version 1 --output-directory ./Generated --namespace MyCompany.Models
Available options:
--schema-registry-url
(required): URL of the Schema Registry--subject
(required): Schema Registry subject name--version
(optional): Schema version (defaults to latest)--output-directory
(optional): Output directory (defaults to ./Generated)--namespace
(optional): Namespace for generated classes (defaults to subject name)
Configuration
The AvroSchema
item supports the following metadata:
SchemaRegistryUrl
- URL of the Schema RegistrySubject
- Schema Registry subject nameVersion
- Schema version (optional, defaults to latest)OutputDirectory
- Directory where the generated classes will be placedNamespace
- Namespace for generated classes (optional, defaults to subject name)
Example
Check out the example project for a complete working example.
How it works
- During build, AvroGen.NET connects to the specified Schema Registry
- Retrieves the Avro schema for the specified subject and version
- Generates C# classes that match the schema structure
- Places generated files in the specified output directory
- Includes generated files in compilation
Generated classes:
- Implement
ISpecificRecord
interface from Apache.Avro - Support serialization/deserialization with Confluent.SchemaRegistry.Serdes.Avro
- Include all necessary properties and data types from the Avro schema
- Maintain schema compatibility for seamless integration with Kafka
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.