20

我创建了一个非常简单的程序,它应该列出 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": { }
  }
}

...我看到一个例外:

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 为目标,所以不应该支持吗?

4

1 回答 1

15

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

我们已经在 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,直到根本问题得到解决。

于 2016-07-13T10:34:21.067 回答