-
Notifications
You must be signed in to change notification settings - Fork 11.1k
C# protoc codegen plugin: Add base_namespace option to grpc_csharp_plugin #28663
Description
Is your feature request related to a problem? Please describe.
This is a follow-up to #13724. It was closed because a workaround was introduced in the Grpc.Tools NuGet package. However, I have a use case that isn't addressed by #17672.
I'm using Buf to generate sources (among other things), and it works for all languages except C# gRPC services (it does work for C# protobuf messages). Buf generates sources directly using the grpc_csharp_plugin through protoc, and this ends up generating duplicate files (leaving me with incomplete generated sources) when two services are in files with the same name but in different directories. For example:
proto\v1\service.protoproto\v2\service.proto
This isn't a problem with protobuf's csharp_plugin thanks to the base_namespace option. However, adding a similar option to grpc_csharp_plugin was rejected in #24426.
Describe the solution you'd like
I'd love to see a native fix to this issue in grpc_csharp_plugin for scenarios where generating sources happens outside MSBuild/through protoc. A couple possible solutions:
- Add a
base_namespaceoption that works likecsharp_plugin's (i.e. reconsider Add generation to multiple directories for C# plugin #24426). - Add any other file name deconfliction algorithm (like random or hash-based file suffixes) to
grpc_csharp_plugin, given how the C# compiler cares very little about the actual file names of the generated sources.
Describe alternatives you've considered
I could assign unique file names to the different services. For example:
proto\v1\service_v1.protoproto\v2\service_v2.proto
However, this would impact the output of other language plugins (e.g. Javascript) and introduce friction elsewhere.
Alternatively-- I could file this as an issue with the Buf project and request they investigate/implement their own workaround for this limitation. I thought about doing that first, but reconsidered after identifying that there are options in most (all?) other protobuf/gRPC plugins to work around duplicate file name issues like this. This just appears to be a limitation of the C# gRPC plugin.