Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate .proto files during build time from a .NET contract assembly #317

Open
rodrigovaras opened this issue Nov 27, 2023 · 5 comments
Open

Comments

@rodrigovaras
Copy link

Hello,
I have a rather complex SDK framework where all of the RPC contracts were defined in C# and marked with DataContract & DataMember attributes. I have recently allowed our RPC services to allow serialize using protobuf protocol with good success.

I'm looking now for a way to produce valid and compatible proto files so we can have regular gRPC clients in other languages to interact with our services.

I understand some there is an API to allow the generation but i would prefer an msbuild task to do this job during build time like the opposite happen from .proto files to C#.
I'm missing a project that show this? Most of the discussion are related to the SchemaGenerator but mostly showing the way to write a tool or doing this on runtime.

Also i notice that most of the .NET API to generate proto is based on a [ServiceContract] attribute. Would like to know if there are other ways to trigger .proto generation for example a set of classes from a namespace regardless they participate on a service contract.
Thanks in advance,

@mgravell
Copy link
Member

Right now, there's no inbuilt mechanism to do this. We have spiked the AOT work for protobuf-net (which shares 95% of the logic with this need) but that is paused at the moment (I've recently shipped Dapper.AOT, and will need to carry over a lot of the learning points from that to this). We're probably another 6 months out from having this, as it needs to come from my free/spare time, unless someone needs it urgently enough to sponsor it.

@rodrigovaras
Copy link
Author

Thanks for the answer and looking forward if this feature become available at some point.

@blackshot
Copy link

blackshot commented Apr 6, 2024

+1 on this, this is the only thing preventing me for using protobuf-net in production, because one of the main features of grpc are contracts that can be used language agnostic. ¿How am i supposed to share contracts with my clients if they don't use C#?

@Ficu
Copy link

Ficu commented Feb 26, 2025

Hi @mgravell,
Any updates on this? We are planning to do slow migration from WCF to gRPC but we cannot add order to the WCF DataMembers (since we have to keep WCF communication alive) which means that currently the best option for us is to generate proto files based on existing contracts. Considering the size of our DataContracts this seems to be only solution for us to achieve the goal in a reasonable time.

@mgravell
Copy link
Member

On the "unable to add order" thing - maybe consider [ProtoContract(InferTagFromName = true)] if the contracts are established and unlikely to suddenly change - obviously this gets tricky if adding new names later, since AardvarkCount displaces all the tags.

On the feature: not currently, I'll need to juggle my workload and see what I can do, but it is hard to make promises since this ultimately comes from my spare time, which is limited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants