I have two proto files, one which is referenced in the other through an import:
syntax = "proto3";
option csharp_namespace = "WeatherMonitorService";
package WeatherService;
import "Protos/weatherMonitor.proto";
...
When I make a service reference to this proto from a client project, it fails with:
../WeatherMonitorService/Protos/weatherService.proto(7,1): error : Import "Protos/weatherMonitor.proto" was not found or had errors.
../WeatherMonitorService/Protos/weatherService.proto(19,12): error : "Monitoring.WeatherData" is not defined.
I added a reference to the second proto file (weathermonitor.proto) for messages only and it still fails. Any ideas on what I'm doing wrong?
Here is the csproj lines for the service references:
<ItemGroup>
<Protobuf Include="..\WeatherMonitorService\Protos\weatherMonitor.proto" GrpcServices="None">
<Link>Protos\weatherMonitor.proto</Link>
</Protobuf>
<Protobuf Include="..\WeatherMonitorService\Protos\weatherService.proto" GrpcServices="Client">
<Link>Protos\weatherService.proto</Link>
</Protobuf>
</ItemGroup>
@shawnwildermuth , according to the documentation when importing another proto file you should specify path relative to the folder where compiler was invoked or pass additional proto paths to compiler to look for the imports.
If we go with the first option, then It means that the import path should be relative to your project root because the compiler is invoked from there by Grpc.Tools.
The import would look like:
import "../WeatherMonitorService/Protos/weatherMonitor.proto"
Hope, that works for you.
Alternatively you could try to dig around of how to pass additional --proto_paths to the Protobuf MS Build tag, I think this options is feasible too.
Two things make this not work:
I can work around this by merging the files, but I'm teaching a course on GRPC so I'm looking for the 'right' way to do this. I might not use the and just relatively build it.
For clarification on the import issue:
./Protos/weatherMonitor.proto : error : Backslashes, consecutive slashes, ".", or ".." are not allowed in the virtual path
Also, not using the link doesn't work either. Still doesn't support the import.
So here is the fix (though I think the tooling should have done this for me):
<ItemGroup>
<Protobuf Include="../WeatherMonitorService/Protos/**/*" GrpcServices="Client"
ProtoRoot="../WeatherMonitorService">
</Protobuf>
</ItemGroup>
Note the ProtoRoot at the project level (not the proto level since imports are by design at the project level). I needed to import both .protos but that's fine.
Most helpful comment
So here is the fix (though I think the tooling should have done this for me):
Note the ProtoRoot at the project level (not the proto level since imports are by design at the project level). I needed to import both .protos but that's fine.