Importing a .proto file into another

I have an apparently simple issue. I have two .proto files, let's say a.proto and b.proto, and b.proto imports a.proto:

b.proto

syntax = "proto3";
package My.Example.Proj;
import "a.proto";
message B {
    ....
    A fromTheOther = 1;
}

a.proto

syntax = "proto3";
package My.Example.Proj;
message A {
   ....
}

In my proto.targets I have the command that compiles the .proto files to C#:

"$(MSBuildThisFileDirectory)......\protobuf\protoc-3.9.2\bin\protoc.exe" --csharp_out=$(SolutionDir)\generated_csharp\ --proto_path=%(RootDir)%(Directory) --error_format="msvs" %(Filename).proto

This command produces indeed A.cs and B.cs, but when I try to use these files in another C# project, I see this compilation error in B.cs (the one that is supposed to use the type A from the other proto):

Error CS0234 The type or namespace name 'A' does not exist in the namespace 'My.Example.Proj' (are you missing an assembly reference?)* at this line in B.cs: public global::My.Example.Proj.A FromTheOther

I'm not sure what am I doing wrong, though I tried several import options, with the same result.

Upvotes: 0

Views: 1889

Answers (1)

Peter Wishart
Peter Wishart

Reputation: 12270

The generated B.cs will not contain the types which b.proto references via import.

Compiling B.cs will therefore require A.cs to be included too.

If you already are including both files, verify that they they are both being generated successfully by protoc and you are including the latest versions.

Upvotes: 2

Related Questions