grpc / grpc-dotnet

gRPC for .NET
Apache License 2.0
4.22k stars 777 forks source link

How to import a proto file that imports other proto files #2533

Open xky0007 opened 2 months ago

xky0007 commented 2 months ago

Suppose I have a file1.proto and it imports file2.proto at other path, file2.proto imports file3.proto at anther path. And many other imports. How can I import file1.proto and use methods inside it with dotnet-grpc tools?

Thanks.

gfoidl commented 2 months ago

See Importing Definitions from Protocol Buffers' documentation.

xky0007 commented 2 months ago

See Importing Definitions from Protocol Buffers' documentation.

I found this. How to set proto_path with dotnet_grpc tools? Because the entry proto file I got from other project is not at root path.

The protocol compiler searches for imported files in a set of directories specified on the protocol compiler command line using the -I/--proto_path flag. If no flag was given, it looks in the directory in which the compiler was invoked. In general you should set the --proto_path flag to the root of your project and use fully qualified names for all imports.

gfoidl commented 2 months ago

See AdditionalImportDirs - Setting location of imported .proto files

entry proto file I got from other project

Out of curiosity: "other project" within the same VS-solution or totally different project (in a different local folder)? When the latter, please think about version control, CI or builds on other machines.