2

This may seem really basic but I'm really new to C# so the google reference docs aren't that clear to me.

They instruct:

protoc --proto_path=bar --csharp_out=src --csharp_opt=base_namespace=Example player.proto

and their example is

protoc --proto_path=src --csharp_out=build/gen --csharp_opt=file_extension=.g.cs,base_namespace=Example src/foo.proto

So my list of basic questions is:

  • For proto_path, is this starting from the top level of the program folder

  • What is the 'bar' option, is it always 'src'?

  • What is the 'src' option, is it always 'build/gen'?

  • Is this copiable? '--csharp_opt=file_extension=.g.cs,base_namespace=MyProgram src/MyProtoFile.proto'

Matthew
  • 41
  • 4
  • See [my answer](https://stackoverflow.com/questions/25452839/protobuf-net-code-generator/71385969#71385969) in a related question. – David Mar 07 '22 at 19:02

1 Answers1

0

For proto_path, is this starting from the top level of the program folder

--proto_path is where the proto files exist that you want converted to cs files. This is relative to the protoc executable but may also be set to a specific location, e.g. --proto_path="C:/myprotofiles/"

What is the 'bar' option, is it always 'src'?

"bar" isn't an option. "foo" and "bar" are commonly used as placeholders when giving generic instructions (https://en.wikipedia.org/wiki/Foobar)

What is the 'src' option, is it always 'build/gen'?

src is not an option. src is a placeholder for a directory. You will replace "src" with the directory containing your proto files.

--csharp_out is where you want the output C# files to go. This is also relative to the protoc executable but may also be set to a specific location, e.g. --csharp_out="C:/mycsfiles/"

Is this copiable? '--csharp_opt=file_extension=.g.cs,base_namespace=MyProgram src/MyProtoFile.proto'

I'm not quite sure of your question here. This is two parts.

--csharp_opt sets options. This example is setting a file_extension to .g.cs (so output files will be somecsfile.g.cs) and also setting a base_namespace to "MyProgram" so all classes generated will be in a namespace called MyProgram.

"src/MyProtoFile.proto," or "src/foo.proto" in Google's example, is a proto file in the /src directory. In our example we would replace this with "c:/myprotofiles/myprotofile.proto"

So, we'd have:

protoc --proto_path="C:/myprotofiles/" --csharp_out="C:/mycsfiles/" --csharp_opt=file_extension=.g.cs,base_namespace=MyProtoFileNamespace "c:/myprotofiles/myprotofile.proto"

Setting explicit paths isn't necessary but hopefully clarifies things (at least for Windows users!)

jhh
  • 663
  • 4
  • 6