1
votes

I'm using Google.Protobuf.Tools in a C# .NET Standard project MyProject. I have multiple proto definitions.

MyProject/Protos/Requests/SampleRequest.proto

syntax = "proto3";

option csharp_namespace = "My.Projects.Protos.Requests";


package sampleRequests;

message SampleRequest {
   int32 requestNumber =1;
   SubRequest request =2;
}


MyProject/Protos/Requests/SubRequest.proto

syntax = "proto3";

option csharp_namespace = "My.Projects.Protos.Requests";

package subRequests;

message SubRequest {
   int32 SubId =1;
   string requestText =2;
}


Now, this code would not compile and the error shown is SubRequest is unknown.

I would like to know how to import a different proto file so that I can achieve this. I don't really understand --proto_path cli options and could not find any clear documentation around this.

Any help is much appreciated. Thanks in advance. Thanks in advance.

1

1 Answers

1
votes

When evaluation an import, it is tested againsts each --proto_path to see if a suitable match can be found. For example, you could have the files side by side in the Requests folder, use --proto_path to give the location of the Protos folder, and talk relative to there inside the proto:

import "Requests/SubRequest.proto";

Note also that you need to think about packages; they aren't in the same package, so you can qualify it explicitly by starting with a .:

syntax = "proto3";
import "Requests/SubRequest.proto";

option csharp_namespace = "My.Projects.Protos.Requests";


package sampleRequests;

message SampleRequest {
   int32 requestNumber =1;
   .subRequests.SubRequest request =2;
}