Skip to content

Grpc.Tools package has MSBuild/XBuild magic to generate C# source code#6062

Closed
aniongithub wants to merge 3 commits intogrpc:masterfrom
aniongithub:master
Closed

Grpc.Tools package has MSBuild/XBuild magic to generate C# source code#6062
aniongithub wants to merge 3 commits intogrpc:masterfrom
aniongithub:master

Conversation

@aniongithub
Copy link
Copy Markdown

The changes in this pull request contain changes that enable users to automagically generate C# source code for .proto files included in their project.

All they have to do is install the Nuget package (and possibly reload their solution). Now the "Build Action" for proto files will contain a new item called "Proto". If selected, these files generate C# in the obj/$(Configuration) folder and include them as part of the build.

This should be completely cross-platform, I've tested it on Windows + VS2013 and OSX + Xamarin Studio.

@jtattermusch, this was the reason I wanted binaries for all platforms in this nuget package. Thanks for helping with that request!

Balasubramaniam, Ananth added 2 commits April 1, 2016 11:06
…ge that includes a "Proto" item type. This automatically builds ProtoBuf and Grpc Sharp wrappers for files that specify this item type and includes the generated C# in the project. Tested on Windows (Visual Studio 2013) and OSX (Xamarin Studio)
Fix a warning from the C# compiler for duplicate cs files included at the compile step
@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@aniongithub aniongithub changed the title Grpc.Tools package has MSBuild magic to generate C# source code Grpc.Tools package has MSBuild/XBuild magic to generate C# source code Apr 1, 2016
@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

3 similar comments
@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@jtattermusch jtattermusch self-assigned this Apr 1, 2016
…nly files that exist (are touchable) make their way into the Compile target.
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Apr 1, 2016
{
try
{
var projectDir = args[0];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform detection code already exists in Grpc.Core.Internal.PlatformApis, having a slightly different version of the same code here feels odd. On the other hand, we can't really make code generator project depend on Grpc.Core. Anyway, I feel like a cleaner solution is needed here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be ok to have this depend on Grpc.Core - because this is a build time only dependency. Unfortunately this class is internal so I can't use it as-is. Would you feel better if I used some other nuget package that included this check? Again, note that this a build-time dependency only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point you can probably just copy-and-paste the PlatformApi class and add a big comment that this is actually what Grpc.Core already implements. Then we are at least duplicating the very same code and we can figure out the rest in the next step.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can do that.

@jtattermusch
Copy link
Copy Markdown
Contributor

this is ok to test

@jtattermusch
Copy link
Copy Markdown
Contributor

I generally like the idea of this contribution - thanks for the pull request. There's a couple of problems though:
-- we need to have a plan how to support this for CoreCLR (msbuild XML files is not how the new .NET projects are built).
-- some way of customizing the codegen args will probably be necessary.
-- Technically this problem is something we should solve in in google/protobuf project first and then apply the same logic for gRPC.

Btw, we already have some related issues: #4805 and protocolbuffers/protobuf#1193. It is probably worth reading through, as it identifies some of the challenges.

Also, CC @jskeet.

@aniongithub
Copy link
Copy Markdown
Author

Closing this pull request. Will reopen with separate Nuget package called Grpc.Tools.MSBuildIntegration that addresses many of the features requested on this thread.

@hcoona
Copy link
Copy Markdown

hcoona commented Jul 31, 2017

However, the #6085 died. Do you have any plan to continue the project or add more advanced support to MSBuild?

@jtattermusch
Copy link
Copy Markdown
Contributor

We might revisit that at some point, but for now, we have no plans to work on that for the next few quarters. Contributions are welcome though (but please be aware that this is a tricky problem to solve and it needs to support more than just trivial .proto files - see previous discussion).

@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants