protobuf c#版本分成两个版本,一个是protobuf-net,另一个是protobuf-csharp-sport
protobuf-net
下载protobuf-net r668,
https://code.google.com/archive/p/protobuf-net/downloads
https://github.com/mgravell/protobuf-net
打开命令行提示符,cd转到C:\Users\slx\Desktop\新建文件夹 (3)\protobuf-net r668\ProtoGen
接下来就可以使用ProgoGen来根据proto脚本生成源代码cs文件了,命令行如下:
protogen -i:test.proto -0:test.cs -ns:MyProtoBuf
-i指定了输入,-o指定了输出,-ns指定了生成代码的namespace
_________________________________________________________________________________________________________________________________
protobuf-csharp-sport
下载地址 http://code.google.com/p/protobuf-csharp-port/
点开“Build”文件夹,
看见那个BuildAll.bat,点击它会自动执行编译操作,编译完成后将出现build_output和build_temp两个输出文件夹,
其中build_output生成的Google.ProtocolBuffers.dll将被用作外部链接的DLL使用,
- ProtoGen.exe - 源代码生成器
- ProtoMunge.exe - tool to remove sensitive data from binary messages
- ProtoDump.exe - tool to dump a binary message as text
- ProtoBench.exe - tool to run performance benchmarks on binary messages
- protoc.exe - 编译脚本工具
打开命令行提示符 ,cd转到 C:\Users\slx\Desktop\protobuf-csharp-port-master\protobuf-csharp-port-master\build_output\tools ,
比如我们要转AddressBook.proto文件。
在命令提示符内输入:
protoc --descriptor_set_out=AddressBook.protobin --include_imports AddressBook.proto
(上述命令之后,你会发现D protoc文件夹内多了一个AddressBook.protobin文件)
接下来:
protogen AddressBook.protobin回车
上述命令之后,D盘protoc文件夹里多了个AddressBook.cs文件,是的,这就是万众瞩目的终极目标文件。