Home > Mobile >  Generate Dotnet GRPC Client code Without CsProj
Generate Dotnet GRPC Client code Without CsProj

Time:06-01

It's possible to use protoc to generate dotnet code in a way that doesn't require a csproj or solution:

protoc -I=$SRC_DIR --csharp_out=$DST_DIR $SRC_DIR/addressbook.proto

Is it possible to do something similar to generate the code for a grpc client/server stub?

CodePudding user response:

Yes - you just need the gRPC plugin, which you can download in the Grpc.Tools package.

You then use:

protoc --grpc_out=$DST_DIR --plugin=protoc-gen-grpc=$GRPC_PLUGIN $SRC_DIR/addressbook.proto`

where GRPC_PLUGIN is the path to grpc_csharp_plugin.exe (or the equivalent binary for your OS) from the NuGet package. Note that the NuGet package is just a zip file really, so you can script downloading it and unzipping it should you wish.

As an example of doing this in a shell script, you could look at the generateprotos.sh script in gax-dotnet - that also gives an example of specifying that you want a .g.cs suffix.

  • Related