Skip to content

Added Grpc.Tools.MSBuildIntegration#6085

Closed
aniongithub wants to merge 6 commits intogrpc:masterfrom
aniongithub:feature-MSBuildIntegration
Closed

Added Grpc.Tools.MSBuildIntegration#6085
aniongithub wants to merge 6 commits intogrpc:masterfrom
aniongithub:feature-MSBuildIntegration

Conversation

@aniongithub
Copy link
Copy Markdown

This new development-only package contains MSBuild integration to allow automagic generation of C# code (and inclusion in the project). Addressed as many concerns as I could based on comments on my previous pull request.

Items can be included for code generation by using

  • Visual Studio or Xamarin Studio GUI by right-clicking on a .proto file included in the project and changing its Build Action to Proto
  • Adding lines directly into the csproj containing a wildcard include that looks like so:
    <Proto Include="*.proto"/> or even <Proto Include="**\*.proto"/>
    This will include all proto files and recursively include proto files from all subdirectories (one-level down)

@jtattermusch, do let me know if this looks good for inclusion. I'm really hoping to get rid of this from my private package feed, so your help is much appreciated. Thanks!

…. This new package contains MSBuild integration to allow automagic generation of C# code (and inclusion in the project). Addressed as many concerns as I could based on comments on my previous pull request.
@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
Copy link
Copy Markdown
Contributor

this is ok to test

@jtattermusch jtattermusch self-assigned this Apr 5, 2016
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
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.

why is the app.config needed?

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.

See here. Although to be fair, since I'm not bundling the exe.config along with the nuget, this can be omitted. I'm ok going either way.

@jtattermusch
Copy link
Copy Markdown
Contributor

#6062

<copyright>Copyright 2015, Google Inc.</copyright>
<tags>gRPC RPC Protocol HTTP/2</tags>
<developmentDependency>true</developmentDependency>
</metadata>
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.

I assume this package cannot depend on Grpc.Tools because that one is a solution level package while this one is project level package. is that right?

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.

That is one reason - the other is that Nuget adds a version number to the directory where the packages are stored. The package cache for the solution could also be arbitary (changed in the Nuget.Config file). Both of these issues mean I'll have to drag in Nuget.Core to examine packages.config and Nuget.Config in order to get at protoc and protobuf_csharp_plugin.

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.

Grpc.Tools does not have to, and should not, IMO, be a solution-level package. Why? A solutions still gets only one copy of a package referenced in multiple projects. Or is there another reason?

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.

The choice to make Grpc.Tools a solution level package is not mine. That said, Grpc.Tools.MSBuildIntegration is not a solution-level package by virtue of having a Build folder with a targets file inside of it.

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.

Let's rather hack it till it works properly! I hope @jtattermusch will not object, will you?

<ItemGroup>
<AvailableItemName Include="Proto"/>
</ItemGroup>
<Target Name="Proto" Inputs="@(Proto)" Outputs="@(Proto->'$(IntermediateOutputPath)%(FileName).cs')">
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.

how is the name of .cs file generated from the name of the .proto file?
Please note that in protoc, foo_examples.proto becomes FooExamples.cs and FooExamplesGrpc.cs

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.

Also the Outputs attribute doesn't seem to list the ...Grpc.cs file.

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.

Comment 1: See lines 20 and 23, I transform the input Proto files into filenames with both variations.

Comment 2: Yes, I simply include them conditionally (only if they exist - the Touch Task takes care of that for me). I could be explicit about including both transformations though. I'll add that in.

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.

Comment 1: See lines 20 and 23, I transform the input Proto files into filenames with both variations.

I do not think I understand how it works. Suppose you have

<Target Name="Proto" Inputs="@(Proto)" Outputs="@(Proto->'$(IntermediateOutputPath)%(FileName).cs')">

In my understanding, if your Proto collection has the only item some_proto.proto, then the Outputs will be obj/Release/some_proto.cs. Since that file will not be made by protoc ever, the target will be rerun every time. The correct name is SomeProto.cs.

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.

Ah, I see. I tested with many files but none had an underscore in their name. Can you think of any other naming changes so I can modify the task/CSharpGenerator to work correctly? Now I'm glad I have the C# based Grpc.Tools.CSharpGenerator to work these things out with

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.

Not only the underscore: some file systems are case-sensitive! So for my proto the generated file My.csmy.cs.

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.

And here's an advantage in writing an MsBuild Task instead: A task can have output parameters, and you can figure out the names programmatically and return them to be used later in the .targets file.

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.

Yes, we would probably need a MsBuild task then. Unfortunately, integrating protoc with msbuild seems to be more complicated than it originally seemed.

@kkm000
Copy link
Copy Markdown
Contributor

kkm000 commented Apr 6, 2016

This is an interesting approach. Generally, when we want to run a tool, writing an MSBuild Task for that is the simplest way to go, as there are APIs to run a process, check files and so on. You write code at a higher level in general.

I will be really happy to contribute and/or guide @ananthonline on that (we adopted gRPC from early alpha straight into production). But it seems to me that a very if not the most important problem here is still not satisfactory solved, namely: If I compile x.proto, y.proto and z.proto, what .cs files will be generated? If I guess wrong, I either cause the project to be recompiled because of missing outputs, or have stale outputs added to compile There is a lot of corner cases, e. g., what happens if I remove the rpc declaration from x,proto and recompile? That's the main thing here to get the build correct, or at the very least as correct as practical for most cases.

@jtattermusch
Copy link
Copy Markdown
Contributor

@kkm000 thanks for great input! Again, this seems to become more complicated than it originally seemed to be.
Because there seems to be lots of problems to solve, I don't think it is likely that we will be able to address everything in a single PR. Can we instead come up with some minimalist set of features that could be checked-in soon and would provide gRPC users some extra comfort when working with .proto files?

Btw, I am not sure if it makes sense to invest a lot of effort into writing a custom msbuild task in times where DNX-style project.json projects are becoming the standard for new projects quickly.

Also, has anyone thought of looking at the problem from a different perspective and coming up with a VS extension that would provide some nice integration for working with .proto files?

@kkm000
Copy link
Copy Markdown
Contributor

kkm000 commented Apr 11, 2016

@jtattermusch: I was thinking about an extension. There is one (https://visualstudiogallery.msdn.microsoft.com/4bc0f38c-b058-4e05-ae38-155e053c19c5, https://github.com/mreu/ProtobufLanguageService). I did not want it at the time because it looked like it did too much. I certainly want syntax highlighting and other support from the editor, and it promises to be really amazing, look at the sample screenshot! It appears, however, that it also generates C# code, and I certainly did not want another compiler in the picture when everything was still in alpha and unraveling... Anyhow, the page now says "C# code generation will follow in Version 2.0" -- I do not remember if the promise was there, but I think I am not the only one complaining! :)

Generally, a VS extension is a greater hurdle to maintain for users and I believe gRPC or protobuf should [edit] not rely on an extension for the whole rig to work. MSBuild is more than enough to have everything built properly. This seems to be true for mono/Xamarin too, but I am not so well versed in DNX project.json builds, however. An extension, on the other hand, would add all the bells and whistles to user experience, including syntax highlighting, syntactic features in editing, creating and adding proto files to projects, but should not go beyond that, IMO. Visual Studio did include some code-behind code generators, but my feeling is this is not where they are going now.

I'll try to wrap my head around the project.json thing. Long overdue, it's been out for a while and I do not even know much beyond the fact it exists!

As for writing and debugging an MSBuild task, this is not hard technically, but needs logistics coordination between protoc and gRPC packages.

@jtattermusch
Copy link
Copy Markdown
Contributor

On Sun, Apr 10, 2016 at 8:44 PM, Kirill Katsnelson <[email protected]

wrote:

@jtattermusch https://github.com/jtattermusch: I was thinking about an
extension. There is one (https://visualstudiogallery.
msdn.microsoft.com/4bc0f38c-b058-4e05-ae38-155e053c19c5,
https://github.com/mreu/ProtobufLanguageService). I did not want it at
the time because it looked like it did too much. I certainly want syntax
highlighting and other support from the editor, and it promises to be
really amazing, look at the sample screenshot! It appears, however, that it
also generates C# code, and I certainly did not want another compiler in
the picture when everything was still in alpha and unraveling... Anyhow,
the page now says "C# code generation will follow in Version 2.0" -- I do
not remember if the promise was there, but I think I am not the only one
complaining! :)

Interesting, the problem I see with the extension for now is that the
protoc and grpc plugins are changing relatively rapidly and with that
frequency of releases, it definitely makes more sense to ship nuget
packages rather than new releases of an VS extension.

Also, some users will be using different versions of protobuf and grpc in
different projects at the same time, which again talks in favor of
per-project nugets.

Generally, a VS extension is a greater hurdle to maintain for users and I
believe gRPC or protobuf should rely on an extension for the whole rig to
work. MSBuild is more than enough to have everything built properly. This
seems to be true for mono/Xamarin too, but I am not so well versed in DNX
project.json builds, however. An extension, on the other hand, would add
all the bells and whistles to user experience, including syntax
highlighting, syntactic features in editing, creating and adding proto
files to projects, but should not go beyond that, IMO. Visual Studio did
include some code-behind code generators, but my feeling is this is not
where they are going now.

I'll try to wrap my head around the project.json thing. Long overdue, it's
been out for a while and I do not even know much beyond the fact it exists!

Two problems with project.json
-- it's way less customizable than MSBuild (no things like custom msbuild
tasks etc).
-- it's been a moving target (things change with deprecation of DNX and
introduction of dotnet CLI)

On the other hand, project.json definitely seems to be the future, so any
solution that doesn't involve it doesn't make much sense in the long run.

As for writing and debugging an MSBuild task, this is not hard
technically, but needs logistics coordination between protoc and gRPC
packages.

We certainly have the power to make changes to both protobuf C# and gRPC C#
(I have commit access to both repos for example). We just need to figure
out what it is that we want to do. I prefer making smaller steps because
because we are unlikely to come up with a grand solution for everything at
once).


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#6085 (comment)

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test.

…X and Linux. The targets file now transforms the list of input proto files into a space separated list and splits them.
@aniongithub
Copy link
Copy Markdown
Author

Ok, I think I've addressed all of the problems that @jtattermusch and @kkm000 pointed out.

It's actually possible to ask protoc to give us the list of dependencies and generated files using the --dependency_out option. The C# wrapper parses the output of this file (for each input proto) and recursively generates C# down to the leaves of the dependency tree. I've verified that this list does indeed work for both XXYYGrpc.cs and XXYYcs files, along with included proto files that are not even included in the project.

See build output from an example here: http://pastebin.com/ruvwM8Df

I've also added a proper clean target that cleans up all generated and temporary files.

Might I suggest we support MSBuild + C# projects and then add support for JSON projects as customizability is added?

Balasubramaniam, Ananth added 3 commits April 22, 2016 14:18
Ensure that clean removes subdirectories created during the protogen phase.
…ectory.

Add boolean flag in ProcessFile to explicitly only include for compilation files that were marked for proto-generation. Don't recursively process all protos, this might cause inclusion of types we didn't intend to compile.
@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test.

@aniongithub
Copy link
Copy Markdown
Author

@jtattermusch @kkm000 , any comments on the latest changes? I believe they address everything we've discussed so far.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test.

1 similar comment
@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test.

@nicolasnoble
Copy link
Copy Markdown
Contributor

What's the status of that PR ? If we still want to proceed with it, it needs some updates.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

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

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link
Copy Markdown
Collaborator

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@jtattermusch
Copy link
Copy Markdown
Contributor

This PR is almost an year old. Closing.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 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.

6 participants