protoc-jar-maven-plugin icon indicating copy to clipboard operation
protoc-jar-maven-plugin copied to clipboard

Add base_namespace option as default for csharp outputTarget to properly generate sources

Open AlexeiZenin opened this issue 2 years ago • 1 comments

Reference: https://developers.google.com/protocol-buffers/docs/reference/csharp-generated#compiler_options

Quote:

base_namespace: When this option is specified, the generator creates a directory hierarchy for generated source code corresponding to the namespaces of the generated classes, using the value of the option to indicate which part of the namespace should be considered as the "base" for the output directory. For example, with the following command-line:

I noticed I had 2 different packages use the same protobuf message name which ended up overwriting another protobuf message in another package when using the csharp compiler via the plugin.

To avoid people not being able to have duplicate messages names in different packages can the plugin just make the csharp implementation set this --csharp_opt=base_namespace= by default to trigger the compiler to generate sub-folders?

AlexeiZenin avatar Aug 03 '21 18:08 AlexeiZenin

For others looking for a quick fix (if this does not become the default), you can use this configuration:

<outputTarget>
       <type>csharp</type>
       <outputDirectory>folder</outputDirectory>
       <outputOptions>base_namespace=</outputOptions>
</outputTarget>

This causes a directory structure to be generated instead of dumping everything in 1 folder which can have overwrite conflicts (silent, so your classes get deleted).

AlexeiZenin avatar Aug 03 '21 18:08 AlexeiZenin