Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xky0007 opened this issue Sep 11, 2024 · 4 comments
Open

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

xky0007 opened this issue Sep 11, 2024 · 4 comments
Labels
question Further information is requested

Comments

@xky0007
Copy link

xky0007 commented Sep 11, 2024

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.

@xky0007 xky0007 added the question Further information is requested label Sep 11, 2024
@gfoidl
Copy link
Contributor

gfoidl commented Sep 11, 2024

See Importing Definitions from Protocol Buffers' documentation.

@xky0007
Copy link
Author

xky0007 commented Sep 12, 2024

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
Copy link
Contributor

gfoidl commented Sep 12, 2024

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.

@ricsiLT
Copy link

ricsiLT commented Dec 16, 2024

If all files are local to you, this could be enough (and you could even drop the <Link> if you don't need it):

    <ItemGroup>
        <Protobuf Include="../../Protos/**/*.proto" GrpcServices="Both" ProtoRoot="../../">
            <Link>Protos\%(RecursiveDir)%(Filename)%(Extension)</Link>
        </Protobuf>
    </ItemGroup>

For files that are external to your project, there are articles online on how to package .proto files correctly in a nuget, similar to how Wellknown .protos are distributed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants