ProtobufNrtAnnotator 0.4.0

dotnet add package ProtobufNrtAnnotator --version 0.4.0
                    
NuGet\Install-Package ProtobufNrtAnnotator -Version 0.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProtobufNrtAnnotator" Version="0.4.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ProtobufNrtAnnotator" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="ProtobufNrtAnnotator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ProtobufNrtAnnotator --version 0.4.0
                    
#r "nuget: ProtobufNrtAnnotator, 0.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ProtobufNrtAnnotator@0.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ProtobufNrtAnnotator&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=ProtobufNrtAnnotator&version=0.4.0
                    
Install as a Cake Tool

ProtobufNrtAnnotator

License: MIT NuGet

Automatically adds nullable reference type (NRT) annotations to C# code generated by Grpc.Tools, since the upstream protoc compiler does not yet support them.

This project is mostly vibe-coded but fully human-reviewed. I wrote this partly to play with Google Antigravity.

Usage

Add the package to your project alongside Grpc.Tools and Google.Protobuf:

<ItemGroup>
  <PackageReference Include="Google.Protobuf" Version="..." />
  <PackageReference Include="Grpc.Tools" Version="..." PrivateAssets="All" />

  <PackageReference Include="ProtobufNrtAnnotator" Version="0.4.0">
    <IncludeAssets>build</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
  </PackageReference>
</ItemGroup>

<ItemGroup>
  <Protobuf Include="yourfile.proto" />
</ItemGroup>

The package automatically processes protobuf-generated C# files during build and adds appropriate nullability annotations.

How It Works

ProtobufNrtAnnotator is an MSBuild task that runs after Grpc.Tools generates C# code from .proto files. It uses Roslyn to:

  1. Parse the generated C# syntax tree
  2. Analyze each property, field, and parameter using semantic information
  3. Determine which reference types should be nullable based on protobuf semantics (e.g., message fields are nullable, but repeated fields and collections are not)
  4. Rewrite the syntax tree with appropriate ? annotations
  5. Save the modified code back to the generated files

This ensures your generated protobuf code works seamlessly with C# nullable reference types enabled.

Development

Releasing a New Version

This project uses GitHub Actions to automatically build, test, and publish to NuGet.org. To release a new version:

  1. Bump the version using Cake:

    dotnet cake --target=BumpVersion --target-version=0.2.0
    

    This will automatically update Directory.Build.props, Directory.Packages.props, and README.md.

  2. Commit and push the version change:

    git commit -am "Bump version to 0.2.0"
    git push
    
  3. Create and push a git tag matching the version:

    git tag v0.2.0
    git push origin v0.2.0
    

The GitHub Actions release workflow will automatically:

  • Build the project
  • Run all tests
  • Pack the NuGet package
  • Publish to NuGet.org using trusted publishing (OIDC authentication)
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0 237 11/23/2025