1

I have an ASP.NET Core 8 project and followed this article:

https://learn.microsoft.com/en-us/aspnet/core/grpc/json-transcoding-binding?view=aspnetcore-8.0

import "google/api/annotations.proto";

I've installed Google.Api.CommonProtos 2.17 nuget package.

But I get:

File not found
Import "annotations.proto" was not found or had errors

3
  • 1
    Your link says : Imported from the google/api/annotations.proto file. The google/api/http.proto and google/api/annotations.proto files need to be in the project. Commented Jul 25 at 21:28
  • Article says files need to be in the project!! what should be the Build action for these files? Commented Jul 28 at 21:03
  • 2
    It is not compiled so there is no build action. It is just read. The folder where the csproj is the main folder and the path that is used for the import statement starts at the root. See following for sample project github.com/dotnet/aspnetcore/tree/main/src/Grpc/JsonTranscoding/… The two file you need are in the api folder. Commented Jul 28 at 21:16

1 Answer 1

0

You need to follow closely the article and refer also to the source code that is linked there.

So in the article you have linked there is written for the example proto file (emphasis mine)

An HTTP rule is:
- An annotation on gRPC methods.
- Identified by the name google.api.http.
- Imported from the google/api/annotations.proto file. The google/api/http.proto and google/api/annotations.proto files need to be in the project.

With that let's look at the source code (linked in the article). For instance we have this src/Grpc/JsonTranscoding/test/testassets/Sandbox/transcoding.proto with this line

import "google/api/annotations.proto";

and the file strcuture is: enter image description here

So as you can see this is just regular file in the project directory, that is imported in proto file.

Going further, let's look at csproj file if there are any special settings for files in the question

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Protobuf Include="greet.proto" GrpcServices="Server" />
    <Protobuf Include="transcoding.proto" GrpcServices="Server" />

    <Reference Include="Grpc.AspNetCore" />
    <Reference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" />
    <Reference Include="Microsoft.AspNetCore.Grpc.Swagger" />
  </ItemGroup>
</Project>

As you can see nothing extra needs to be set for those files, there are only configuration for proto files that you create.

So to sum up: get files from the example project that is linked, download or copy those files in your project and then you must reference them from your proto files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.