Protobuf Compiler in a C# Shared Library

542 views
Skip to first unread message

Chris Langlois

unread,
Apr 18, 2021, 2:43:47 PM4/18/21
to Protocol Buffers
I'm using Protobuf and Visual Studio C#. I have a Client project, Server project, and and shared project. I want my proto file and messages to live within the shared project. I'm installed the Nuget packages for protobuf, protobuf tools, grpc, grpc core, and grpc tools into both my client and server projects (you cant add them to a shared project). The build action for the proto file in my shared project cannot be changed to Protobuf compiler for automatic compilation like it can if I put the .proto in either the client or server project.

Any thoughts on a better architecture or what I might be doing wrong here. This seems like it should be a common architecture but it seems to be a real struggle.

Thanks!

Marc Gravell

unread,
Apr 18, 2021, 2:56:38 PM4/18/21
to Chris Langlois, Protocol Buffers
What is stopping you from adding them to the shared project? What TFM is it targeting? This should JustWorkTM. You could also look at the csproj changes in the client and server, and try to apply the same changes in the shared project - it might tell you why it isn't happy.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/e9a8e8e4-e085-47aa-8f62-c34d65e9b11an%40googlegroups.com.

Chris Langlois

unread,
Apr 18, 2021, 6:08:11 PM4/18/21
to Protocol Buffers
Thanks for the recommendations. I can add .proto files to the Shared projects. What I cannot do is add a build action for "protobuf compiler" to enable automatic compilation in Visual Studio. For some reason that doesn't seem to work within a shared project in particular.  I tried manually adding the PackageReference includes for protobuf and grpc that appear in the client and server projects to the shared project .projitems file and it doesn't seem to make any difference.
Thanks

Marc Gravell

unread,
Apr 19, 2021, 2:36:57 AM4/19/21
to Chris Langlois, Protocol Buffers
The tooling package you need here is Grpc.Tools, which should work fine in a class library.



--
Regards,

Marc
Reply all
Reply to author
Forward
0 new messages