'How to import protobuf well-known types in AspNet Core gRPC Service
I', scratching my head about how to import "google/protobuf/empty.proto" to my proto file. What I'm doing so far:
In my .csproj file, I added the following:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> </PropertyGroup> <ItemGroup> <Protobuf Include="C:\Users\me\.nuget\packages\google.protobuf.tools\3.10.0\tools\google\protobuf\*.proto" GrpcServices="Server"/> <Protobuf Include="Protos\*.proto" GrpcServices="Server" /> </ItemGroup> <ItemGroup> <PackageReference Include="Grpc.AspNetCore" Version="2.23.2" /> <PackageReference Include="System.Reactive" Version="4.1.6" /> </ItemGroup> </Project>
In my project folder, I have a folder called "Protos" where I have a test.proto file in which I would like to use the "empty.proto" like:
import "google/protobuf/empty.proto";
However, I get the error File not found in project
. I also do not like to specify the "3.10.0" in the ItemGroup
. What is the correct way to use google protobuf well-known types?
Solution 1:[1]
if you are using resharper just follow the pic
reason of this issue : Though Protobuf is purely path-based and will work once the file in found on your hard disk ReSharper needs all the files added to solution in order to process them and Current implementation of included files' search inside protobuf support does not allow to find the files outside the solution.
have good time
Solution 2:[2]
Well known protos (such as empty.proto) actually get special handling in the Grpc.Tools package - the import path for well known .proto files is added automatically and the generated code is already part of Google.Protobuf itself.
They only thing you need to do in your proto file is to add "import "google/protobuf/empty.proto" and after then you can use google.protobuf.Empty type in messages normally. No other steps are needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amin Fayazi |
Solution 2 | Jan Tattermusch |