AvroGen.NET
0.1.0
See the version list below for details.
dotnet add package AvroGen.NET --version 0.1.0
NuGet\Install-Package AvroGen.NET -Version 0.1.0
<PackageReference Include="AvroGen.NET" Version="0.1.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add AvroGen.NET --version 0.1.0
#r "nuget: AvroGen.NET, 0.1.0"
// Install AvroGen.NET as a Cake Addin #addin nuget:?package=AvroGen.NET&version=0.1.0 // Install AvroGen.NET as a Cake Tool #tool nuget:?package=AvroGen.NET&version=0.1.0
AvroGen.NET
AvroGen.NET is a library for automatic generation of C# classes from Avro schemas stored in Confluent Schema Registry. It provides both a programmatic API for integration into your applications and a command-line tool for quick class generation.
Installation
NuGet Package
dotnet add package AvroGen.NET
Command Line Tool
dotnet tool install --global --add-source ./nupkg AvroGen.NET.Tool
Usage
Programmatic Way
using AvroGen.NET;
var config = new SchemaGeneratorConfig
{
SchemaRegistryUrl = "http://localhost:8081",
OutputDirectory = "./generated"
};
var generator = new SchemaGenerator(config);
await generator.GenerateClassFromSchema("user-value", 1);
Command Line Way
After installing the global tool, you can use it to generate classes:
avrogennet --schema-registry-url http://localhost:8081 --subject user-value --schema-version 1 --output ./generated
Parameters:
--schema-registry-url
- Schema Registry URL--subject
- Schema subject name in Schema Registry--schema-version
- Schema version--output
- Path for saving generated class
Features
- Automatic C# class generation from Avro schemas
- Integration with Schema Registry
- MSBuild task for seamless build process integration
- Support for schema versioning
- Clean and maintainable generated code
- NuGet package for easy distribution
Configuration Options
Subject
: The Schema Registry subject nameVersion
: The schema version to use (optional, defaults to latest)SchemaRegistryUrl
: URL of your Schema Registry instanceOutputPath
: Directory where generated classes will be placed
Example
Here's a complete example of how to use AvroGen.NET in your project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<GeneratedCodePath>$(MSBuildProjectDirectory)\Generated</GeneratedCodePath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AvroGen.NET" Version="1.0.0" />
<PackageReference Include="Confluent.SchemaRegistry" Version="2.3.0" />
<PackageReference Include="Confluent.SchemaRegistry.Serdes.Avro" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<AvroSchema Include="Schemas\test-schema.avsc">
<Subject>test-schema-value</Subject>
<Version>1</Version>
<SchemaRegistryUrl>http://localhost:8081</SchemaRegistryUrl>
<OutputPath>$(GeneratedCodePath)</OutputPath>
</AvroSchema>
</ItemGroup>
</Project>
Requirements
- .NET 8.0 or later
- Access to a Schema Registry instance
- MSBuild 17.0 or later
Building from Source
- Clone the repository:
git clone https://github.com/iiitpux/AvroGen.NET.git
- Build the solution:
dotnet build
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Apache Avro for the Avro serialization system
- Confluent Schema Registry for schema management
- The .NET community for inspiration and support
Local Development
Requirements
- .NET 8.0 SDK
- Docker and Docker Compose (for local Schema Registry)
Environment Setup
- Start local Schema Registry:
cd infrastructure
./start.ps1
- Stop local environment:
cd infrastructure
./stop.ps1
Project Structure
src/
- source codeAvroGen.NET/
- main libraryAvroGen.NET.Tool/
- command line tool
tests/
- testsAvroGen.NET.UnitTests/
- unit testsAvroGen.NET.IntegrationTests/
- integration tests
examples/
- usage examplesinfrastructure/
- files for local developmentdocs/
- documentationbuild/
- build artifactsschemas/
- Avro schema examples
Configuration Options
Subject
: Schema Registry subject nameVersion
: Schema versionSchemaRegistryUrl
: Schema Registry URLOutputPath
: Generated files pathNamespace
: Namespace for generated classesGenerateAsync
: Generate async serialization methodsGenerateEquality
: Generate equality comparison methodsGenerateJsonMethods
: Generate JSON serialization methods
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
Acknowledgments
- Apache Avro for the Avro serialization system
- Confluent Schema Registry for schema management
- The .NET community for inspiration and support
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. |
-
net8.0
- Apache.Avro (>= 1.12.0)
- Confluent.SchemaRegistry (>= 2.6.1)
- Confluent.SchemaRegistry.Serdes.Avro (>= 2.6.1)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.