Protobuf Not Working - Jetbrains Rider .NET Core 3.1

Viewed 2231

I am trying to do a simple gRPC tutorial. Initial I started with Jetbrains Rider by creating a new gRPC service, then I created a console app for the client and installed:

Google.Protobuf - 3.11.4
Grpc.Net.Client - 2.28.0-pre2
Grpc.Tools - 2.28.0-pre3

It doesn't look like the generated code for the greet.proto is being generated as I am getting red squigglies var client = new Greeter.GreeterClient(channel);

However, when I open the project in Visual Studio, everything seems to work. Am I missing a plugin or something here?

My csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp3.1</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Google.Protobuf" Version="3.11.4" />
      <PackageReference Include="Grpc.Net.Client" Version="2.28.0-pre2" />
      <PackageReference Include="Grpc.Tools" Version="2.28.0-pre3" />
    </ItemGroup>

    <ItemGroup>
      <Protobuf Include="Protos\greet.proto">
        <GrpcServices>Client</GrpcServices>
        <OutputDir>obj\Debug\netcoreapp3.1\</OutputDir>
        <Access>Public</Access>
        <ProtoCompile>True</ProtoCompile>
        <ProtoRoot></ProtoRoot>
        <CompileOutputs>True</CompileOutputs>
        <Generator>MSBuild:Compile</Generator>
      </Protobuf>
    </ItemGroup>

</Project>
2 Answers

if it compiles in Rider (compiled files should be in folder obj/Debug/[your-netcore-target]/), then you have it set up correctly and it works (= it compiles). "Only" Rider has trouble to find compiled classes (tested in Rider 2019.3.4 build 193.6494.48).

It seems to be a bug (see https://youtrack.jetbrains.com/issue/RIDER-25412 or https://youtrack.jetbrains.com/issue/RIDER-39721) in Rider which is caused by mixing NuGet versions.

Make sure all other projects within your solution uses the same versions of gRPC related libs.

I managed to set it with these versions (targeting netcoreapp3.0):

My Server app:

<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />

My client app

<PackageReference Include="Google.Protobuf" Version="3.11.2" />
<PackageReference Include="Grpc.Net.Client" Version="2.25.0" />
<PackageReference Include="Grpc.Tools" Version="2.27.0">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  <PrivateAssets>all</PrivateAssets>
</PackageReference>

Beware that Grpc.AspNetCore in version 2.27.0 contains references to Google.Protobuf 3.11.2 and Grpc.Tools 2.27.0. So I cannot use different versions in my client project. Or I can, it will compile but Rider won't find the files.

Simply said make sure that all gRPC related nugets within all projects in you solution use the exact same version, including referenced nugets (referenced by the nugets you explicitly use).

Hope it helps

Try deleting the projects obj directory, and reloading the solution.

Related