C # file generation with Google protocol errors

I am working on a project that uses Java, C #, as well as C ++ applications. I am trying to use the Google protocol buffer to communicate between them. I use the following .proto file, which was taken from examples:

package tutorial; message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; } repeated PhoneNumber phone = 4; } message AddressBook { repeated Person person = 1; } 

I mean the following tutorial: https://developers.google.com/protocol-buffers/docs/csharptutorial

Textbooks for other languages ​​also exist.

I tried the following command line arguments for each language:

Java

C: \ ProtoBuf \ protoc -I = C: \ trash --java_out = C: \ trash C: \ trash / addressbook.proto

C ++

C: \ ProtoBuf \ protoc -I = C: \ trash --cpp_out = C: \ trash C: \ trash / addressbook.proto

C # :

C: \ ProtoBuf \ protoc -I = C: \ trash --csharp_out = C: \ trash C: \ trash / addressbook.proto

Java and C ++ compilations work fine even with some warning in case of Java. But I get the following output with C # :

- csharp_out: protoc-gen-csharp: the system cannot find the specified file.

I use this compiler: https://github.com/google/protobuf/releases/download/v2.6.1/protoc-2.6.1-win32.zip

What am I doing wrong here? Do I need other files to compile C #?

+6
source share
3 answers

I know how to generate proto files in C #

  • open visual studio, open nuget command line, type: Install-Package Google.ProtocolBuffers , link: Google.ProtocolBuffers 2.4. 1.555
  • find package /Google.ProtocolBuffers.2.4.1.555/tools/ProtoGen.exe
  • use the command line, enter: ProtoGen.exe addressbook.proto -output_directory = C: \ trash

I am writing a python script in proto proto gen.py files

 import os, subprocess, threading def main(): with open("conf.txt") as file: exe = os.path.join(os.getcwd(), "..\\Package\\Google.ProtocolBuffers.2.4.1.555\\tools\\ProtoGen.exe") out = "-output_directory=%s" % (os.path.join(os.getcwd(), "..\\Common\\libs\\protos")) def gen(proto): subprocess.check_call([exe, os.path.join("protos", proto), out]) list = [] for proto in file.read().split(','): t = threading.Thread(target = gen, args = (proto, )) t.start() list.append(t) for t in list: t.join() if __name__ == '__main__': main() 

conf.txt

 base.proto,test.proto,addressbook.proto 
+4
source

You are trying to generate C # files using the old protoc version

protoc-2.6.1-win32.zip

C # code generator for proto-2 and proto3 was introduced only in Version 3.0.0-alpha-3

Two new language implementations (Objective-C, C #) are introduced in proto3.

So download protoc Version 3.0.0-alpha-3 , install it and call: protoc -I=$SRC_DIR --csharp_out=$DST_DIR $SRC_DIR/your.proto

Beware that started with Version 3.0.0-beta-1 The C # code generator only supports proto3 generation:

The semantics of Proto3 are supported; Proto2 files are forbidden for C # codegen

+6
source

I solved all my problems using / (slash) integer \ (anti-slash) all the way.

protoc.exe -I = D: / dev / xyz / projects --csharp_out = d: / temp D: /dev/xyz/projects/messages.proto

0
source

All Articles