1

sample.proto

package Busy.Proto;
option optimize_for = SPEED;

message BusyRequest { required string message = 1;}
message BusyResponse {required string message = 1;} 
service BusyService {rpc Send (BusyRequest) returns (BusyResponse);}

.cs在包管理器控制台中通过以下命令生成文件

ProtoGen.exe sample.proto -output_directory="C:\SomeDir"

结果sample.cs文件

 // Generated by ProtoGen, Version=2.4.1.555, Culture=neutral, PublicKeyToken=55f7125234beb589.  DO NOT EDIT!
 #pragma warning disable 1591, 0612, 3021
 #region Designer generated code

 using pb = global::Google.ProtocolBuffers;

 ...

  #region Services
  /*
  * Service generation is now disabled by default, use the following option to enable:
  * option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;
  */
 #endregion

 ...

试过了

  • ProtoGen.exe sample.proto -output_directory="C:\SomeDir" option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;在包管理器控制台中运行。以错误结束

术语“google.protobuf.csharp_file_options”未被识别为名称..

  • 加入。option service_generator_type = GENERIC;_ sample.proto以错误结束

无法解析符号

如何启用Services生成?

4

2 回答 2

1

使用最新版本的 protogen,您还可以通过 services 选项来生成服务: protogen --csharp_out=. --proto_path=. +services=true *.proto

我用 protobuf-net.Protogen --version 3.0.0-alpha.122 进行了测试,它似乎不适用于 2.3.17(截至今天的最后一个稳定版本)

于 2020-02-12T15:48:56.573 回答
0

在此处的讨论中找到答案

ProtoGen.exe -service_generator_type=GENERIC sample.proto  -output_directory="someDIR"
于 2016-07-09T13:28:57.887 回答