ProtoGenNet 0.0.1.12
dotnet add package ProtoGenNet --version 0.0.1.12
NuGet\Install-Package ProtoGenNet -Version 0.0.1.12
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="ProtoGenNet" Version="0.0.1.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ProtoGenNet" Version="0.0.1.12" />
<PackageReference Include="ProtoGenNet" />
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 ProtoGenNet --version 0.0.1.12
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ProtoGenNet, 0.0.1.12"
#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 ProtoGenNet@0.0.1.12
#: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=ProtoGenNet&version=0.0.1.12
#tool nuget:?package=ProtoGenNet&version=0.0.1.12
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ProtoGen - C# to Protocol Buffer Generator
ProtoGenNet is a C# console application that automatically generates .proto files from C# classes.
Getting Started
default command line
$(ProjectDir)../ClientInterfaceCs/bin/$(Configuration)/net9.0/ClientInterfaceCs.dll
full command line
$(ProjectDir)../ClientInterfaceCs/bin/$(Configuration)/net9.0/ClientInterfaceCs.dll client_interface_cs_package $(ProjectDir)/../Protos/icalculatorservice.proto
Features
- Attribute-Based Generation: Uses
[Browsable(true)]attributes on classes to control what gets included in the generated.protofile - Automatic Type Mapping: Maps C# types (primitives, classes, structs, enums, collections) to Protocol Buffer types
How It Works
1. Proto Generation from C# Classes
Classes decorated with [Browsable(true)] are used as service definitions. All virtual methods in the class are included as RPC methods.
[Browsable(true)]
public class SampleService
{
public virtual string GetGreeting(string name)
{
// Implementation
}
public virtual UserProfile GetUserProfile(string userId)
{
// Implementation
}
// This method is NOT included (not virtual)
void InternalMethod()
{
// Implementation
}
}
2. Generated Proto Output
The above class generates:
syntax = "proto3";
package sample;
service SampleService {
rpc GetGreeting (GetGreetingRequest) returns (GetGreetingResponse) {}
rpc GetUserProfile (GetUserProfileRequest) returns (UserProfile) {}
}
message GetGreetingRequest {
string name = 1;
}
message GetGreetingResponse {
string value = 1;
}
message GetUserProfileRequest {
string userId = 1;
}
message UserProfile {
PersonInfo person = 1;
Address address = 2;
repeated string interests = 3;
}
3. Type Mapping
ProtoGen automatically maps C# types to Protocol Buffer types:
| C# Type | Proto Type |
|---|---|
bool |
bool |
int, short, byte, sbyte |
int32 |
long |
int64 |
uint, ushort |
uint32 |
ulong |
uint64 |
float |
float |
double, decimal |
double |
string |
string |
byte[] |
bytes |
enum |
enum (generated) |
List<T>, T[] |
repeated T |
| Classes/Structs | message (generated) |
void, Task |
google.protobuf.Empty |
Project Structure
ProtoGen/
├── ProtoGen.csproj # Project file with NuGet dependencies
├── Program.cs # Demo application
├── Generator/
│ ├── ProtoGenerator.cs # Main proto file generator
│ ├── TypeMapper.cs # C# to Protobuf type mapping
│ └── ProtoFileWriter.cs # (future: file writing utilities)
└── Samples/
├── SampleService.cs # Example service class
└── SampleModels.cs # Example data models
Dependencies
- Google.Protobuf (3.32.1) - Protobuf runtime
- Grpc.Core (2.46.6) - gRPC runtime
- Grpc.Tools (2.72.0) - Build-time proto compilation
Usage
Running the Demo
cd ProtoGen
dotnet run
This will:
- Generate a
.protofile from classes decorated with[Browsable(true)] - Save it to
../Protos/<service_name>.proto - Display the generated content
Generating Proto from Your Own Class
var generator = new ProtoGen.Generator.ProtoGenerator
{
PackageName = "myapp",
ServiceName = "MyService"
};
var protoContent = generator.GenerateProto(typeof(MyService));
File.WriteAllText("my_service.proto", protoContent);
Complete Workflow
- Define Class: Create C# class with
[Browsable(true)]attribute on the class - Mark Methods: Make methods virtual to include them in the service
- Generate Proto: Run ProtoGen to create
.protofile - Compile Proto: Use
Grpc.Toolsto generate C# gRPC client/server code - Implement Server: Create gRPC server implementing the service
Key Design Decisions
Why [Browsable(true)]?
- Existing attribute from
System.ComponentModel - Semantic meaning: "expose this to external systems"
- No custom attributes needed
- Works well with PropertyGrid and other reflection tools
- Applied only to classes to mark them as service definitions
Why Virtual Methods Only?
- Ensures interface compatibility
- Prevents generation of non-overrideable methods
- All virtual methods in
[Browsable(true)]classes are automatically included
Why Wrapper Messages for Primitives?
- gRPC best practices recommend message types for requests/responses
- Allows future extensibility (add fields without breaking changes)
- Avoids proto3 limitations with primitive types
- Consistent patterns across all RPC methods
Limitations
- Only supports
[Browsable(true)]on classes for filtering (not on interfaces or methods) - No support for client/server streaming (yet)
- No support for bidirectional streaming (yet)
- Decimal types map to double (proto3 limitation)
- No circular reference detection (can cause stack overflow)
Future Enhancements
- Support for streaming RPC patterns
- Custom attribute support beyond
[Browsable] - Circular reference detection
- Source generator version (compile-time)
- Integration with ASP.NET Core gRPC
- Support for proto options and annotations
- Validation rule generation
- Method-level filtering support
Example Output
See sample_service.proto for example generated output from SampleService.
License
Part of the FlexUI gRPC examples project.
| 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.
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.0.1.12 | 686 | 12/3/2025 |
| 0.0.1.11 | 677 | 12/3/2025 |
| 0.0.1.10 | 126 | 11/29/2025 |
| 0.0.1.9 | 183 | 11/28/2025 |
| 0.0.1.8 | 187 | 11/27/2025 |
| 0.0.1.7 | 195 | 11/25/2025 |
| 0.0.1.6 | 194 | 11/25/2025 |
| 0.0.1.5 | 410 | 11/20/2025 |
| 0.0.1.4 | 409 | 11/20/2025 |
| 0.0.1.3 | 404 | 11/19/2025 |
| 0.0.1.2 | 408 | 11/19/2025 |
| 0.0.1.1 | 415 | 11/19/2025 |