【问题标题】:Protobuf Not Working - Jetbrains Rider .NET Core 3.1Protobuf 不工作 - Jetbrains Rider .NET Core 3.1
【发布时间】:2020-03-18 10:28:03
【问题描述】:

我正在尝试做一个简单的 gRPC 教程。最初我通过创建一个新的 gRPC 服务开始使用 Jetbrains Rider,然后我为客户端创建了一个控制台应用程序并安装:

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

它看起来不像为 greet.proto 生成的代码正在生成,因为我得到了红色的波浪线 var client = new Greeter.GreeterClient(channel);

但是,当我在 Visual Studio 中打开项目时,似乎一切正常。我在这里缺少插件或其他东西吗?

我的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>

【问题讨论】:

    标签: asp.net-core jetbrains-ide


    【解决方案1】:

    如果它在 Rider 中编译(编译后的文件应该在文件夹 obj/Debug/[your-netcore-target]/ 中),那么您已经正确设置它并且它可以工作(= 它编译)。 “仅”Rider 无法找到已编译的类(在 Rider 2019.3.4 build 193.6494.48 中测试)。

    这似乎是 Rider 中的一个错误(参见 https://youtrack.jetbrains.com/issue/RIDER-25412 或 https://youtrack.jetbrains.com/issue/RIDER-39721),这是由混合 NuGet 版本引起的。

    确保您的解决方案中的所有其他项目都使用相同版本的 gRPC 相关库。

    我设法用这些版本进行了设置(针对 netcoreapp3.0):

    我的服务器应用:

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

    我的客户端应用

    <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>
    

    注意,2.27.0 版中的 Grpc.AspNetCore 包含对 Google.Protobuf 3.11.2 和 Grpc.Tools 2.27.0 的引用。所以我不能在我的客户项目中使用不同的版本。或者我可以,它会编译,但 Rider 找不到文件。

    简单地说,确保您解决方案中所有项目中所有与 gRPC 相关的 nuget 都使用完全相同的版本,包括引用 nuget(由您明确使用的 nuget 引用) .

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      尝试删除项目 obj 目录,然后重新加载解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-01
        • 1970-01-01
        相关资源
        最近更新 更多