0

I'm trying to link protobuf together from different projects in my solution. I seem to get File Not Found errors every time I build and can't find a way for the protobuf compiler to find the files.

The following protobuf files i'm using also a note that I trimmed some small things.

Project A

Service/Identity/Protos/User.Proto

import "Identity/Protos/Common.proto";

option csharp_namespace = "Service.Identity";

package user;

service ProfileController {
    rpc CreateProfile(CreateProfileRequest) returns (common.GenericResult);
}

Project B

Shared/Protos/Common.Proto

option csharp_namespace = "Shared";

package common;

message GenericResult {
    bool success = 1;
    string exceptions = 2;
}

In the csproj files the following settings have been made.

Project A

  <ItemGroup>
    <Protobuf Include="Identity\Protos\User.proto" GrpcServices="Server" />
    <Protobuf Include="..\Shared\Protos\Common.proto" Link="Identity\Protos\Common.proto" ProtoRoot=".." GrpcServices="None" >
    </Protobuf>

Project B

  <ItemGroup>
    <Protobuf Include="Protos\Common.proto" GrpcServices="None" />
  </ItemGroup>

The link seems to work but I can't import it in my user.proto Common Link

When I try and import it which I have tried in the following import statements in my user.proto seems to be able to find it.

import "Identity/Protos/Common.proto";
import "Protos/Common.proto";
import "Common.proto";
import "/Identity/Protos/Common.proto";

It gives me the following error. enter image description here

All i want to do is be able to use the Common.Proto in my User.Proto. But it just does not work.

Kevindt12
  • 109
  • 1
  • 10

1 Answers1

1

Probably you have to set your User.proto as a Link too.

<ItemGroup>
   <Protobuf Include="..\Identity\Protos\User.proto" Link="Identity\Protos\User.proto" ProtoRoot=".." GrpcServices="Server" />
   <Protobuf Include="..\Shared\Protos\Common.proto" Link="Identity\Protos\Common.proto" ProtoRoot=".." GrpcServices="None" />
</ItemGroup>

And also I will rather use Common.proto's original folder structure not changing it to Identity\Protos\Common.proto. It could be confusing in the future.

I have configured it like this:

<!-- External project protobufs -->
<Protobuf Include="..\MultipleProtobufFiles.Contracts\Configuration\user_configuration.proto" GrpcServices="None" ProtoRoot="..">
    <Link>MultipleProtobufFiles.Contracts\Configuration\user_configuration.proto</Link>
</Protobuf>
    

<!-- This project service protobuf -->
<Protobuf Include="..\MultipleProtobufFiles\server_communication.proto" GrpcServices="Both" ProtoRoot="..">
    <Link>server_communication.proto</Link>
</Protobuf>

Maybe it will help, I fought with it few days ago and won in the end.

TondaMarko
  • 11
  • 3