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
Grpc.Tools is not passing OutputOptions or AdditionalProtocArguments to protoc.exe #25950
Comments
related #25930 |
Neither I updated my proj file to <Protobuf Include="Protos\example_data_payloads.proto" GrpcServices="None" ProtoCompile="true" AdditionalProtocArguments="--csharp_opt=file_extension=.g.cs"/>
<Protobuf Include="Protos\example_data_schema.proto" GrpcServices="None" ProtoCompile="true" OutputOptions="csharp_opt=file_extension=.g.cs"/> and the proj build log (set to detailed) search results for "protoc.exe" have this... (line breaks added to readability)
@jtattermusch - these were added from this commit was it working for you then? I dont mind trying an older version but I dont know which version to pick. |
|
CC @moserware |
I took a quick look into this and there seems to be two possible issues:
to:
Then you'll see that user-provided MSBuild
You'll see that
Alternatively, you could use the new
and
In either case, Thus, to the best of my knowledge, this issue isn't caused by the new |
I have been tinkering with a workaround because of a separate issue (poor code coverage exclusion) where I tried to get the files to contain a ".g.cs" extension so that I can globally exclude the ".g.cs" files from code coverage. In general, the MSBuild targets can be extended (read hacked) to correct the expected outputs: <ItemDefinitionGroup>
<Protobuf_Compile>
<_OutputOptions>%(Protobuf_Compile._OutputOptions);file_extension=.g.cs</_OutputOptions>
</Protobuf_Compile>
</ItemDefinitionGroup>
<Target Name="_test" AfterTargets="Protobuf_PrepareCompile;Protobuf_PrepareClean">
<ItemGroup>
<New_Protobuf_ExpectedOutputs Include="@(Protobuf_ExpectedOutputs -> '%(RootDir)%(Directory)%(Filename).g.cs')" />
<Protobuf_ExpectedOutputs Remove="@(Protobuf_ExpectedOutputs)" />
<Protobuf_ExpectedOutputs Include="@(New_Protobuf_ExpectedOutputs)" />
</ItemGroup>
</Target> HOWEVER a bigger problem was found. The grpc csharp plguin does not respect the file_extension option in regards to the generated services. If you run grpc/src/compiler/csharp_plugin.cc Line 48 in 2d4f3c5
In the lines following the command line parameters are interpreted and can easily (probably, unless I missed something) look for these options similar to how the standard protobuf csharp compiler operates: edit: included additional msbuild hacks |
Summary of above for my benefit:
|
Created a fix for including the |
#30410 is now merged and some useful insights are in #25950 (comment) and #25950 (comment). |
What version of gRPC and what language are you using?
Grpc.Tools 2.36.4
What operating system (Linux, Windows,...) and version?
Windows 10 + Linux (current, idk)
What runtime / compiler are you using (e.g. python version or version of gcc)
Whatever Grpc.Tools uses
What did you do?
I have included 3 proto files in a VS project. Two are compiled and are simple message payloads. The third is linked from here and compiled by another proj file.
For the two that are proto compiled in this project, I am trying to fix the file extension to note that the file has been code generated so it can be excluded from test coverage reports. OutputOptions is described here and I've tried a few variations of it but the file is still generated as a .cs file.
What did you expect to see?
the code file generated with a .g.cs extension
What did you see instead?
just the file with a .cs extension in the obj/ directory
The proto file for the first item is
the code is otherwise generated correctly. I would really prefer the exclusion mechanism to be part of the compiled output, like a [GeneratedCode] attribute, since analyzers may be working from the compiled output and not using source analysis. The current conventions used by the proto generation are not any of the common ways to designate code thats been generated.
The text was updated successfully, but these errors were encountered: