AvroGen.NET.Tool 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global AvroGen.NET.Tool --version 0.1.0                
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.1.0                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=AvroGen.NET.Tool&version=0.1.0                
nuke :add-package AvroGen.NET.Tool --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 name
  • Version: The schema version to use (optional, defaults to latest)
  • SchemaRegistryUrl: URL of your Schema Registry instance
  • OutputPath: 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

  1. Clone the repository:
git clone https://github.com/iiitpux/AvroGen.NET.git
  1. 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

Local Development

Requirements

  • .NET 8.0 SDK
  • Docker and Docker Compose (for local Schema Registry)

Environment Setup

  1. Start local Schema Registry:
cd infrastructure
./start.ps1
  1. Stop local environment:
cd infrastructure
./stop.ps1

Project Structure

  • src/ - source code
    • AvroGen.NET/ - main library
    • AvroGen.NET.Tool/ - command line tool
  • tests/ - tests
    • AvroGen.NET.UnitTests/ - unit tests
    • AvroGen.NET.IntegrationTests/ - integration tests
  • examples/ - usage examples
  • infrastructure/ - files for local development
  • docs/ - documentation
  • build/ - build artifacts
  • schemas/ - Avro schema examples

Configuration Options

  • Subject: Schema Registry subject name
  • Version: Schema version
  • SchemaRegistryUrl: Schema Registry URL
  • OutputPath: Generated files path
  • Namespace: Namespace for generated classes
  • GenerateAsync: Generate async serialization methods
  • GenerateEquality: Generate equality comparison methods
  • GenerateJsonMethods: Generate JSON serialization methods

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

Acknowledgments

License

MIT

Product 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.

Version Downloads Last updated
0.5.47 186 1/23/2025
0.5.4 188 12/26/2024
0.3.15 134 12/22/2024
0.3.12 143 12/21/2024
0.2.0 161 12/21/2024
0.1.0 130 12/21/2024