'How to import shared proto file into local one?

I have project Protobuf.Shared which contains shared proto files. This project is packed into NuGet package.

Project structure:

- .nuspec
- proto
 - shared.proto
 - base.proto
- Dummy.cs

Also I have project Protobuf.Server, which uses Protobuf.Shared NuGet package and also contains own proto file.

Project structure:

- proto
 - server.proto
- Dummy.cs

I successfully imported shared proto files, they are correctly compiled during build action. In Dummy.cs I can use generated message classes.

Problem:

When I want to import shared.proto (from Protobuf.Shared) into server.proto build action fails with error that shared.proto not found. How to import proto in this case correctly to get successful project build? Usage of shared protos via NuGet package is a requirement.

I made a sample at GitHub with readme to save your time.

Result of server.proto I want to achieve:

syntax = "proto3";

package server;

option csharp_namespace = "Protobuf.Server";

// Import shared.proto somehow
import "shared.proto";
//import "1.0.0/shared.proto";

message SomeMessage {
  int32 Amount = 1;
  //shared.Name name = 2;
}


Solution 1:[1]

When I downloaded and checked the code, the generation type of the 'shared.proto' file in the 'Protobuf.Shared' project was not selected, and when I made it 'Client and Server' and created and updated the nuget package, the problem was solved.

I added this in 'protobuf.Shared.csproj'

<ItemGroup>
  <Protobuf Update="proto\shared.proto" GrpcServices="Both" />
</ItemGroup>

You can also do this in the properties of the 'shared.proto' file.

enter image description here

I also sent a pull request to the repo.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1