无需CSPROJ生成dotnet grpc客户端代码

发布于 2025-02-03 07:21:38 字数 193 浏览 2 评论 0原文

可以使用ProtoC以不需要CSPROJ或解决方案的方式生成dotnet代码:

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

是否可以执行类似的操作以生成GRPC客户端/服务器存根的代码?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韵柒 2025-02-10 07:21:38

是的 - 您只需要GRPC插件,您可以在grpc.tools软件包中下载。

然后使用:

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

where grpc_plugingrpc_csharp_plugin.exe(或Nuget软件包的等效二进制文件)的路径。请注意,Nuget软件包实际上只是一个zip文件,因此您可以在愿意的情况下脚本下载并解压缩。

作为在shell脚本中执行此操作的一个示例,您可以查看 gax -dotnet中的generateProtos.sh脚本 - 还提供了一个指定您想要.g.cs后缀的示例。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文