c# - 为什么 Google.Pubsub.V1 beta01 不适用于 dotnet cli 项目?

标签 c# google-cloud-platform grpc dotnet-cli

我创建了一个非常简单的程序,它应该列出 Google Cloud 项目中可用的主题。代码很简单:

using System;
using Google.Pubsub.V1;

public class Test
{
    static void Main()
    {
        var projectId = "(fill in project ID here...)";
        var projectName = PublisherClient.FormatProjectName(projectId);
        var client = PublisherClient.Create();
        foreach (var topic in client.ListTopics(projectName))
        {
            Console.WriteLine(topic.Name);
        }
    }    
}

当我从针对 .NET 4.5 的“常规”msbuild 项目运行它时,它工作正常。当我尝试将 dotnet cli (1.0.0-preview2-003121) 与以下 project.json 文件一起使用时:

{
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Google.Pubsub.V1": "1.0.0-beta01"
  },
  "frameworks": {
    "net45": { }
  }
}

...我看到一个异常(exception):

Unhandled Exception: System.IO.FileNotFoundException: Error loading native library.
Not found in any of the possible locations c:\[...]\Pubsub.Demo\bin\Debug\net45\win7-x64\nativelibs\windows_x64\grpc_csharp_ext.dll
   at Grpc.Core.Internal.UnmanagedLibrary.FirstValidLibraryPath(String[] libraryPathAlternatives)
   at Grpc.Core.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives)
   at ...

我没有尝试以 .NET Core 为目标,所以这不应该受到支持吗?

最佳答案

这是目前 gRPC 0.15 中的一个限制,Google.Pubsub.V1 将其用作其 RPC 传输。在 msbuild 下,Grpc.Core 包中的 build/net45/Grpc.Core.targets 文件将所有 native 二进制文件复制到位。在 DNX 下,包未被复制,gRPC 尝试使用本地包存储库在正确的位置查找文件。在 dotnet cli 下,我们需要使用包中的“runtimes”根目录来托管库。

我们已经 implemented a fix for this in gRPC ,但我们未能将其纳入 beta-01 版本。我们希望为 beta-02 修复它。

可以通过手动复制文件来解决这个问题:

mkdir bin\Debug\net45\win7-x64\nativelibs\windows_x64
copy \users\jon\.dnx\packages\Grpc.Core\0.15.0\build\native\bin\windows_x64\grpc_csharp_ext.dll bin\Debug\net45\win7-x64\nativelibs\windows_x64

...但这显然很繁琐。我建议只使用 msbuild,直到根本问题得到解决。

关于c# - 为什么 Google.Pubsub.V1 beta01 不适用于 dotnet cli 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38349230/

相关文章:

c# - 如何正确绑定(bind)到数据模板中的 Itemsource

c# - Hangfire 自定义状态过期

由于维护,Compute Engine 上的 MySQL 未正确关闭

go - 由 grpc proto3 生成的 protobuff 中的蛇形格样式

c++ - 无法生成 gRPC 服务类

node.js - gRPC DEADLINE_EXCEEDED 即使服务器已启动并且

c# - 如何在 C# 中为 webclient 设置端口?

c# - Winforms 标签文本未完全显示

google-cloud-platform - 使用 Google Cloud Storage 托管图像共享网站的图像

ssl - 如何修复 GCloud App Engine ERR_SSL_PROTOCOL_ERROR?