ProtobufNrtAnnotator 0.4.0
dotnet add package ProtobufNrtAnnotator --version 0.4.0
NuGet\Install-Package ProtobufNrtAnnotator -Version 0.4.0
<PackageReference Include="ProtobufNrtAnnotator" Version="0.4.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ProtobufNrtAnnotator" Version="0.4.0" />
<PackageReference Include="ProtobufNrtAnnotator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ProtobufNrtAnnotator --version 0.4.0
#r "nuget: ProtobufNrtAnnotator, 0.4.0"
#:package ProtobufNrtAnnotator@0.4.0
#addin nuget:?package=ProtobufNrtAnnotator&version=0.4.0
#tool nuget:?package=ProtobufNrtAnnotator&version=0.4.0
ProtobufNrtAnnotator
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:
- Parse the generated C# syntax tree
- Analyze each property, field, and parameter using semantic information
- Determine which reference types should be nullable based on protobuf semantics (e.g., message fields are nullable, but repeated fields and collections are not)
- Rewrite the syntax tree with appropriate
?annotations - 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:
Bump the version using Cake:
dotnet cake --target=BumpVersion --target-version=0.2.0This will automatically update
Directory.Build.props,Directory.Packages.props, andREADME.md.Commit and push the version change:
git commit -am "Bump version to 0.2.0" git pushCreate 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)
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 |