I have an aspnetcore application that's using Grpc, and is currently working fine with a simple message containing only strings.
I need to add a new message that will contain money values, and I saw that there is a money.proto type available by importing google/protobuf. However, when I try to import it, I get an error.
I added the following in my proto file:
import "google/protobuf/money.proto";
I expected the Grpc Money type to be generated during the build, and complete successfully.
However, the build fails and I get the following errors:
Import "google/protobuf/money.proto" was not found or had errors.
"google.protobuf.Money" is not defined
I found this question asked previously, and the answer was to disable protobuf support in ReSharper. However, when I checked this setting, the box was already unchecked by default, as shown below:
This follow-up comment stated that these proto files are available in the Grpc.Tools nuget package, which I have installed in my project:
This similar question had the same answer.
I was able to find the file itself on github here, and used it to confirm that I had the casing correct (import statement lower-case m, type usage upper-case M). I noticed that the package for this file was 'google/type' and not 'google/protobuf', so I tried changing my import statement and usages to match, but it had no effect on the problem, same errors.
I checked here to see if there was any documentation on how to get this working, and all they had to say was this:
Which, if I'm reading it correctly, suggests that if I have a working Grpc setup, then I should have this available.
Finally, I found this article suggesting that these files must be manually copy/pasted into your project, but that seems quite primitive? Surely there's a way to pull these in automatically through nuget or something?
I've been unable to find any further guidance on the topic. Any help would be greatly appreciated.
My apologies it's taken me this long to get back with an update, but I believe I've got it all sorted now.
The tl;dr is that I needed to do the following to fix the problem:
Server csproj:
<ItemGroup>
<Protobuf Include="Proto\example.proto" GrpcServices="Server" AdditionalImportDirs="..\..\BuildingBlocks\googleapis" />
<Protobuf Include="..\..\BuildingBlocks\googleapis\google\type\money.proto" />
</ItemGroup>
Client csproj:
<ItemGroup>
<Protobuf Include="../GrpcExample.Server/Proto/example.proto" GrpcServices="Client" AdditionalImportDirs="..\..\BuildingBlocks\googleapis" />
<Protobuf Include="..\..\BuildingBlocks\googleapis\google\type\money.proto" />
</ItemGroup>
I've created a github repo with an example client/server project that shows working code on how to set this all up, and a README that walks you through step-by-step how to go from 2 web API projects to Money working over gRPC.