grpc / grpc-dotnet

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

Client project does not resolve client classes generated by Grpc.Tools (client .cs files are generated in obj folder) #2542

Closed sethsnel closed 2 months ago

sethsnel commented 2 months ago

Question

Having to manually include .cs files seems a no-op, and is also not mentioned by any tutorials or resources. How can I use the generated classes/clients from the .proto files without including generated client classes from the obj/ folder?

My situation and setup

I've verified wether I've followed the correct steps using these resources:

What I've setup:

On the server side

I've created a .proto file and derived a concrete implemantation. This implementation can find the generated MijnSBBServices.MijnSBBServicesBase in obj/Debug/net8.0/Protos/MijnsbbGrpc.cs.

image

image

On the client side

I've created the .proto file. A client cs file is generated in obj/Debug/net8.0/Protos/MijnsbbGrpc.cs. However, I'm not able to instantiate a client object unless I include these .cs files in my project.

image

image

image

What have I tried and verified?

I've verified that I installed the correct Nuget packages for the client project:

image

I've verified that the project got the correct protobuff information in an itemgroup:

image

I've tried including the generated .cs files in the obj folder, as a result I'm able to instantiate a grpc client and even run/debug the setup:

image

However, this seems to be a no-op and is undesirable. (to manually include the generated files from the obj/ folder). Please see question at top.

sethsnel commented 2 months ago

It turns out that there were rules that removed files from obj/ from compilation. After commenting out these lines and reload the project the generated grpc client namespace could be found and and the client instantiated. I'm not sure how these lines ended up in my project file, I haven't added them consciously in any case. Answer can be resolved. Perhaps troubleshooting documentation could be expanded to check on lines that modify the use of classes in obj/ folder.

image