Reputation: 563
I'm struggling writing the right configuration for grpc imports.
So the .net solution structure is like:
\Protos\Common\common.proto
\Protos\Vehicle\car.proto
\CarMicroservice
Inside car.proto I have: import "common.proto"
What I want is the generated grpc code to be inside the project CarMicroservice.
Inside CarMicroservice.csproj I have written the path to the protos:
<Protobuf Include="common.proto" ProtoRoot="..\Protos\Common\" />
<Protobuf Include="car.proto" ProtoRoot="..\Protos\Vehicle\" />
But getting error: 'common.proto' no such file or directory
The question is: How do I correctly import common.proto inside the car.proto?
Note: I already looked at the similar issue, but couldn't make it work for my case
Importing .proto files from another project
Upvotes: 9
Views: 12171
Reputation: 1872
Alternatively, there are two other ways to specify include directories for protoc
.
First, there is a global property named Protobuf_AdditionalImportsPath
. If you specify this property in your .csproj
/.fsproj
, it will be passed on to protoc
for every .proto
in that project. You can use it like this:
<PropertyGroup>
<Protobuf_AdditionalImportsPath>../../my/other/directory</Protobuf_AdditionalImportsPath>
</PropertyGroup>
There is also a AdditionalImportDirs
property you can specify directly on <Protobuf>
elements. This will likely only be valid for the .proto
s you specify it on:
<Protobuf Include="MyProto.proto" Link="MyProto.proto" AdditionalImportDirs="../../my/other/directory" />
Keep in mind that in both cases, you can specify any directory you want, regardless of whether it is a parent of the .proto
you're compiling.
Also keep in mind that the import path you specify in your .proto
needs be relative to one of the import directories you specify.
Upvotes: 5
Reputation: 563
Ok, I finally solved the issue. Also @DazWilkin pointed it out.
import
, so you should use absolute path of the project. In my case it was: import "Common/common.proto"
ProtoRoot="..\Protos\Common\"
use ProtoRoot="../Protos/"
"..\Protos\
<Protobuf Include="Common/common.proto" ProtoRoot="../Protos/" />
<Protobuf Include="Vehicle/car.proto" ProtoRoot="../Protos/" />
Upvotes: 13