英文:
error while building gRPC service in .net 6
问题
我尝试按照此教程的步骤,但无法运行 gRPC 服务。以下是输出:
原始输出文本:
生成开始...
1>------ 生成开始: 项目: GrpcGreeter,配置: 调试 Any CPU ------
1>生成开始于 2023年12月3日 03:04:46。
1>目标 GenerateTargetFrameworkMonikerAttribute:
1> 跳过目标“GenerateTargetFrameworkMonikerAttribute”,因为所有输出文件都是基于输入文件的最新状态。
1>目标 _Protobuf_CoreCompile:
1> C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\build\_protobuf\Google.Protobuf.Tools.targets(280,5): 错误 MSB6006: "C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\tools\windows_x64\protoc.exe" 退出代码为 -1073741819。
1>在项目“GrpcGreeter.csproj”中的目标“_Protobuf_CoreCompile”生成完成 -- 失败。
1>
1>在项目“GrpcGreeter.csproj”中生成完成 -- 失败。
1>
1>生成失败。
1>
1>C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\build\_protobuf\Google.Protobuf.Tools.targets(280,5): 错误 MSB6006: "C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\tools\windows_x64\protoc.exe" 退出代码为 -1073741819。
1> 0 个警告
1> 1 个错误
1>
1>用时 00:00:01.70
========== 生成: 0 个成功,1 个失败,0 个最新,0 个跳过 ==========
========== 生成于凌晨3:04,共耗时02,212秒 ==========
我尝试过使用 .NET 5、6 和 7,但不幸的是都没有成功。
我怀疑问题可能与 nuget 包路径中的非ASCII字符有关,但我不确定。在此提前感谢任何帮助。
编辑:
以下是我的 proto 文件。我没有对它做任何更改,它已经由 Visual Studio 自动生成。
```protobuf
syntax = "proto3";
option csharp_namespace = "GrpcGreeter";
package greet;
// 问候服务定义。
service Greeter {
// 发送问候
rpc SayHello (HelloRequest) returns (HelloReply);
}
// 包含用户姓名的请求消息。
message HelloRequest {
string name = 1;
}
// 包含问候的响应消息。
message HelloReply {
string message = 1;
}
以及 GreeterService.cs(也是自动生成的):
using Grpc.Core;
using GrpcGreeter;
namespace GrpcGreeter.Services
{
public class GreeterService : Greeter.GreeterBase
{
private readonly ILogger<GreeterService> _logger;
public GreeterService(ILogger<GreeterService> logger)
{
_logger = logger;
}
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
{
return Task.FromResult(new HelloReply
{
Message = "Hello " + request.Name
});
}
}
}
英文:
I try to follow this tutorial, but I can't run the gRPC service. Here is the output:
Raw output text:
Build started...
1>------ Build started: Project: GrpcGreeter, Configuration: Debug Any CPU ------
1>Build started 12.03.2023 03:04:46.
1>Target GenerateTargetFrameworkMonikerAttribute:
1> Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>Target _Protobuf_CoreCompile:
1> C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\build\_protobuf\Google.Protobuf.Tools.targets(280,5): error MSB6006: "C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\tools\windows_x64\protoc.exe" exited with code -1073741819.
1>Done building target "_Protobuf_CoreCompile" in project "GrpcGreeter.csproj" -- FAILED.
1>
1>Done building project "GrpcGreeter.csproj" -- FAILED.
1>
1>Build FAILED.
1>
1>C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\build\_protobuf\Google.Protobuf.Tools.targets(280,5): error MSB6006: "C:\Users\Paweł\.nuget\packages\grpc.tools.40.0\tools\windows_x64\protoc.exe" exited with code -1073741819.
1> 0 Warning(s)
1> 1 Error(s)
1>
1>Time Elapsed 00:00:01.70
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 3:04 AM and took 02,212 seconds ==========
I was trying with .net 5, 6 and 7, but unfortunately with no success.
I suspect, the problem might be with non-ascii characters in path to nuget packages, but I'm not sure. Thank you in advance for any help.
EDIT:
Here's my proto file. I haven't changed anything here, it was already generated by vs.
syntax = "proto3";
option csharp_namespace = "GrpcGreeter";
package greet;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply);
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings.
message HelloReply {
string message = 1;
}
and GreeterService.cs (also auto-generated):
using Grpc.Core;
using GrpcGreeter;
namespace GrpcGreeter.Services
{
public class GreeterService : Greeter.GreeterBase
{
private readonly ILogger<GreeterService> _logger;
public GreeterService(ILogger<GreeterService> logger)
{
_logger = logger;
}
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
{
return Task.FromResult(new HelloReply
{
Message = "Hello " + request.Name
});
}
}
}
答案1
得分: 1
验证 greet.proto 文件的属性...
-
构建操作 - Protobuf 编译器
-
gRPC 存根类 - 仅服务器端
如果你无法看到这些属性,你也可以在项目文件中检查。
完成验证后,重新构建项目。
英文:
Verify greet.proto properties...
-
Build Action - Protobuf compiler
-
gRPC Stub Classes - Server only
If you are not able to see properties, you can check in project file as well.
Once you verify this, re-build project.
答案2
得分: 0
谢谢大家的帮助。我已经知道问题出在哪里了。事实证明,我的包路径中确实存在非ASCII字符(ł)的问题。解决方法是将 .nuget 目录从默认位置移动到另一个目录(路径中只包含ASCII字符)。然后,您需要在解决方案中添加一个 nuget.config 文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="[rel_path]\.nuget\packages" />
<add key="repositoryPath" value="[rel_path]\.nuget\packages" />
</config>
</configuration>
其中 [rel_path] 是相对于 nuget.config 文件的当前位置的移动 .nuget 目录的相对路径。不过还是要感谢您的帮助。
英文:
Thank you all for your help. I already know what was wrong. It turned out, that it indeed was a problem with non-ascii character (ł) in my path to packages. The solution was to move .nuget directory from my default location to some other directory (with ascii-only characters in path). Then you need to add nuget.config file to solution with this content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="[rel_path]\.nuget\packages" />
<add key="repositoryPath" value="[rel_path]\.nuget\packages" />
</config>
</configuration>
Where [rel_path] is relative path to your moved .nuget directory. Of course relative to current location of nuget.config file. Thank you for your help though.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论