question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable referencing proto files in NuGet packages

See original GitHub issue

A common pattern in other languages is that your proto files are not part of your project, especially if you are a client but ofter also when you are a server.

Certainly in enterprises that have their stack build on gRPC. What you see is that the proto’s are managed in a common mono repo for all contracts (were talking mono-repo for the proto files only here). What you then often see is that contract repo has a language specific distribution step. This do not create client libraries, they just publish the proto files in a package format idiomatic to the language (an example is Java: they package the proto files in a jar package and publish them to a maven repo, in general a private one of the company).

What I like to see is that the .NET implementation would be able to reference proto in NuGet that it can fetch from a NuGet repository. That will make it easier for enterprises to adapt gRPC in .NET. They only need to add the NuGet distribution step in one place and a project just need to references NuGet as an external dependency.

Let me also stress that this is distributing the proto files and not client libraries. You want to avoid distribution of clients that are build with an older version of proto as the one you are using in your project.

And example how this works in Java (using gradle):

dependencies {
    compile("com.google.protobuf:protobuf-java:3.6.1")
    compile("io.grpc:grpc-protobuf:1.18.0")
    protobuf('io.anemos:protobeam-options-proto:0.0.3-SNAPSHOT')
}

The 3th dependency points to an artifact just containing proto, gradle will make sure that client/server stubs are generate with the same version of gRPC and protobuf as the project is.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:30
  • Comments:42 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
ghostcommented, Aug 27, 2019

If you want to ship .proto files in a nuget package for reuse in .proto files in your own project you can do this:

<ItemGroup>
  <PackageReference Include="MyCompany.ProtoBuf" Version="1.0" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
  <Protobuf Include="Grpc/*.proto" GrpcServices="Both" CompileOutputs="true" AdditionalImportDirs="$(PkgMyCompany_ProtoBuf)/content/Proto" ProtoRoot="Grpc" />
</ItemGroup>

The key here are the GeneratePathProperty and AdditonalImportDirs attributes.

In the MyCompany.ProtoBuf package you need to have something like this:

<ItemGroup>
    <Content Include="Proto\**\*.proto">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemGroup>

to get the proto files inlcuded.

15reactions
stueeeycommented, Oct 13, 2020

Hey @JamesNK @jtattermusch , what needs to happen here? It seems like there is demand for this, what needs to happen for the pr to be accepted?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Sharing one gRPC proto file for all solutions
I've tried creating a separate solution and placing the proto files there then reference it to all other solutions but couldn't make it...
Read more >
Protocol Buffers/gRPC Codegen Integration Into .NET Build
Tools NuGet package provides C# tooling support for generating C# code from .proto files in .csproj projects: It contains protocol buffers compiler and...
Read more >
Protocol Buffers/gRPC Integration Into .NET Build
I just want to compile .proto files into my library · “Classic” .csproj with packages.config (Visual Studio, Mono): This is handled automatically by...
Read more >
Referencing other proto files
You can reference other proto files from inside your proto file. Another similarity between Protobuf and any major programming language is that you...
Read more >
Manage Protobuf references with dotnet-grpc
Create a Protobuf reference from a remote file specified by a URL. Ensure the correct gRPC package dependencies are added to the project....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found