question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

proto files nested files?

See original GitHub issue

I would like to split my proto file as follows:

syntax = "proto3";

option csharp_namespace = "GrpcService2";

package greet;
import "pkg1/greet.proto";

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (greet_types.HelloRequest) returns (greet_types.HelloReply);
}

and

syntax = "proto3";

option csharp_namespace = "GrpcService2";

package greet_types;

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings.
message HelloReply {
  string message = 1;
}

So in the file system it looks as follows image

But when I build the project there is an error: image

I have also prepared a repo with this issue (https://github.com/MihailsKuzmins/GrpcService2) Basically it is the standard project, but only greet.proto is split.

So, is it possible to accomplish what I want (split generation rpc and models). My goal: generate models in the base project; generate client / server in child projects.

If it is not possible I will simply change gRPC models with other models, but I would like to keep gRPC models (less duplication) Any help is much appreciated 🙏

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MihailsKuzminscommented, Oct 15, 2021

@chwarr, thank you for the example, I have applied it in my final solution. I think it helped me solve the problem

@JamesNK looks like I have managed to get it working by changing the file name to greet_types.proto. When files have the same names nothing worked on my PC even after clean-rebuild and after deleting bin and obj folders image

after several hours of brainstorming (cleaning, rebuilding, reopening my IDE) I have finally achieved what I wanted. Indeed after I split proto files Visual Studio started to complain about compiling, but restarting the IDE solved these errors

GrpcBase.csproj - proto files, generate base types

<ItemGroup>
	<Protobuf Include="messages\base\*.proto" GrpcServices="None" />
</ItemGroup>

GrpcMediatr.csproj - generate MediatR implementations

<ItemGroup>
	<Protobuf Include="..\GrpcBase\messages\*.proto" GrpcServices="None" ProtoRoot="..\GrpcBase">
		<Link>Protobufs\%(RecursiveDir)%(FileName)%(Extension)</Link>
	</Protobuf>
</ItemGroup>

GrpcService.csproj - gRPC server

<ItemGroup>
	<Protobuf Include="..\GrpcBase\*.proto" GrpcServices="Server" ProtoRoot="..\GrpcBase">
		<Link>Protobufs\%(RecursiveDir)%(FileName)%(Extension)</Link>
	</Protobuf>
</ItemGroup>

And my protos image

greet.proto

syntax = "proto3";

option csharp_namespace = "GrpcService2";

package greet;
import "messages/greet_types.proto";

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (greet_types.HelloRequest) returns (greet_types.HelloReply);
}

greet_types.proto

syntax = "proto3";

option csharp_namespace = "GrpcService2";

package greet_types;
import "messages/base/base_types.proto";

// The request message containing the user's name.
message HelloRequest {
	string name = 1;
	.base_types.TestEnum test = 2;
}

// The response message containing the greetings.
message HelloReply {
	string message = 1;
}

base_types.proto

syntax = "proto3";

option csharp_namespace = "GrpcService2";

package base_types;

// The request message containing the user's name.
message TestEnum {
	string name = 1;
}

@JamesNK, please carry on with the awesome gRPC stuff. I really appreciate what you are doing for the community

0reactions
JamesNKcommented, Oct 14, 2021

@JamesNK, does not seem to work 😢

You might need to clean the solution and rebuild. I needed to do that when I tested your scenario out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Splitting protocol buffer definitions into multiple .proto files
Show activity on this post. import "myproject/base.proto";. Docs: https://developers.google.com/protocol-buffers/docs/proto#importing.
Read more >
Nested protobuf file folders and cmake flattening the ...
I've tried making each subfolder a library and then linking them together into one 'meta'-library, which fixes the first two problems, but then ......
Read more >
Protobuf - Nested Class
Protobuf Nested Class - Here, we will see how to create a nested class. ... to use the protoc binary to create the...
Read more >
Language Guide (proto 2) | Protocol Buffers Documentation
This guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to...
Read more >
gRPC: Import nested proto files - OSS Support
Greetings! I try to use gRPC client like this: const client = new grpc.Client(); client.load( [PROTO_PATH] // some global path ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found