Added Grpc.Tools.MSBuildIntegration#6085
Conversation
…. 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.
|
Can one of the admins verify this patch? |
3 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
this is ok to test |
| @@ -0,0 +1,6 @@ | |||
| <?xml version="1.0" encoding="utf-8" ?> | |||
There was a problem hiding this comment.
why is the app.config needed?
There was a problem hiding this comment.
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.
| <copyright>Copyright 2015, Google Inc.</copyright> | ||
| <tags>gRPC RPC Protocol HTTP/2</tags> | ||
| <developmentDependency>true</developmentDependency> | ||
| </metadata> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')"> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Also the Outputs attribute doesn't seem to list the ...Grpc.cs file.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Not only the underscore: some file systems are case-sensitive! So for my proto the generated file My.cs≠my.cs.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, we would probably need a MsBuild task then. Unfortunately, integrating protoc with msbuild seems to be more complicated than it originally seemed.
|
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 |
|
@kkm000 thanks for great input! Again, this seems to become more complicated than it originally seemed to be. 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? |
|
@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. |
|
On Sun, Apr 10, 2016 at 8:44 PM, Kirill Katsnelson <[email protected]
Interesting, the problem I see with the extension for now is that the Also, some users will be using different versions of protobuf and grpc in
Two problems with project.json On the other hand, project.json definitely seems to be the future, so any
|
|
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.
|
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? |
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.
|
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test. |
|
@jtattermusch @kkm000 , any comments on the latest changes? I believe they address everything we've discussed so far. |
|
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
|
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test. |
|
What's the status of that PR ? If we still want to proceed with it, it needs some updates. |
|
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test. |
|
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
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
This PR is almost an year old. Closing. |
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
<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!