Generation of C# files with Google Protocol Fails

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

protoc-2.6.1-win32.zip

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

Introduced two new language implementations (Objective-C, C#) to 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 from Version 3.0.0-beta-1 C# code generator only supports generating proto3:

Proto3 semantics supported; proto2 files are prohibited for C# codegen


I know how to gen proto files in c#

  1. open visual studio, open nuget command line, type : Install-Package Google.ProtocolBuffers , link : Google.ProtocolBuffers 2.4.1.555
  2. find Package/Google.ProtocolBuffers.2.4.1.555/tools/ProtoGen.exe
  3. use command line, type : ProtoGen.exe addressbook.proto -output_directory=C:\trash

I write a python script to gen proto files, gen.py

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