views:

63

answers:

2

I am attempting to use the same .proto file (protobuf) for a C# and a C++ project. My problem is that the C# file requires an import and some options set (protobuf-csharp-port) while the C++ file doesn't.

Is there any way I can tell protoc to ignore imports/options under certain circumstances?

Currently my only way around this is to create two different .proto files, and update both when changes are made.

A: 

Could you just have your proto files without import then proto files for C# that have required imports and import your original files?

Klaim
+1  A: 

Ah, this chestnut :(

Yes, it's a pain. No, I don't have a really nice way round it at the moment. I'd like a way of saying, "This imported file is only for extension options, and those extensions can be assumed to be available: include the values in the descriptor set, but don't try to resolve the extensions." Unfortunately there's no way of doing that.

What you can do is just include the C# options when you build the C++ version, and you'll end up with a C++ representation of your C# options. It's not pretty, but it won't actually do any harm. I've not actually done this in C++, but I've ended up generating the Java files for the C# options for exactly this reason before now.

If you have any other suggestions for how I could change the C# port to improve this, I'd be interested in hearing them...

Jon Skeet