Reputation: 503
I am not able to include protos present in Project A in a project B. The idea would be to have the protos with GrpcServices="Server"
in project A and in project B, of tests, include the same protos but, now, as GrpcServices="Client"
ProjectA/Protos/Profile.proto
syntax = "proto3";
package profile;
option csharp_namespace = "ProjectA.Protos";
import "google/protobuf/empty.proto";
service ProfileService {
rpc Get(google.protobuf.Empty) returns (Profile);
}
message Profile {
string profile_id = 1;
string description = 2;
}
ProjectA/Protos/User.proto
syntax = "proto3";
package user;
option csharp_namespace = "ProjectA.Protos";
import "google/protobuf/wrappers.proto";
import "Protos/Profile.proto";
service UserService {
rpc Get(google.protobuf.StringValue) returns (UserDetail);
}
message UserDetail {
string id = 1;
string name = 2;
repeated profile .Profile profiles = 7;
}
Project B .csproj (The test project)
<ItemGroup>
<Protobuf Include="..\ProjectA\Protos\*.proto" GrpcServices="Client" ProtoRoot="Protos">
<Link>Protos\*.proto</Link>
</Protobuf>
</ItemGroup>
With these settings I always end up having this error return
error : File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
Upvotes: 1
Views: 5104
Reputation: 503
Bringing a return on the applied solution.
The problem that occurs when trying to do this import in the same solution is that each inclusion in a .csproj
it will try to generate C# classes and these classes are generated with "global context" and this prevents the generation of "server" and "client" classes because they would have the same names.
The easiest solution was to add Both
to the proto file's include configuration. Thus, the generated C# classes already contemplate the client and server side, so it is possible to use them both in project A (server) and in project B (client).
<Protobuf Include="Protos\*.proto" GrpcServices="Both" />
The solution presented by Jan Tattermusch, in the comments, would have a project C with only the protos files, would follow the same configuration and is also a great alternative.
Upvotes: 7