Jon*_*eet 19 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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我从针对.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": { }
}
}
Run Code Online (Sandbox Code Playgroud)
......我看到一个例外:
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 ...
Run Code Online (Sandbox Code Playgroud)
我不是要尝试以.NET Core为目标,所以不应该支持它吗?
Jon*_*eet 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
Run Code Online (Sandbox Code Playgroud)
......但这显然非常繁琐.我建议只使用msbuild直到底层问题得到解决.
| 归档时间: |
|
| 查看次数: |
1277 次 |
| 最近记录: |