csharp_namespace 值中存在句点时 Protobuf 编译器错误

问题描述 投票:0回答:1

我正在尝试将我的原型添加到现有的公共库中,以便我的客户端和服务器可以导入它并与任何更改保持同步。

我将 Grpc.AspNetCore、Google.Protobuf 和 Grpc.Tools 添加到项目中:

<PackageReference Include="Google.Protobuf" Version="3.25.2" />
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" />
<PackageReference Include="Grpc.Tools" Version="2.61.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

(但我很确定唯一需要的是

Grpc.AspNetCore

我在项目中包含了 .proto 文件,作为客户端和服务器:

<ItemGroup>
   <Protobuf Include="./Protos/MyProto.proto" GrpcServices="Server" ProtoRoot="./Protos/" />
   <Protobuf Include="./Protos/MyProto.proto" GrpcServices="Client" ProtoRoot="./Protos/" />
</ItemGroup>

我创建了文件:

syntax = "proto3";
package myproto_grpc;

option csharp_namespace = "Existing.Library.Namespace.gRPC";

service MyService {
    rpc Message (MessageRequest) returns (Reading);
}

message MessageRequest {}

message Reading{
    string id = 1;
    int32 value = 2;

    enum Polarity {
        Unspecified = 0;
        Positive = 1;
        Negative = 2;
    }
    
    Polarity polarity = 3;
    bool is_something = 4;
}

每当我构建项目时,我都会收到错误:

严重性代码描述项目文件行抑制状态详细信息 错误 CA1708“命名空间”和“现有、现有”的名称应不只区分大小写 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1708)

最关键的是,如果我将

csharp_namespace
更改为任何没有
.
的值,它编译得很好;任何带有
.
的值 - 即使像
Random.Name
这样完全随机的值也不会编译。

我是 gRPC 和 protobuf 的新手,所以我可能错过了一些明显的东西。

protocol-buffers grpc protobuf-net grpc-c#
1个回答
0
投票

试试这个:

<ItemGroup>
   <Protobuf Include="./Protos/MyProto.proto" GrpcServices="Both" ProtoRoot="./Protos/" />
</ItemGroup>

这可以避免两次发出输出的共享部分。

© www.soinside.com 2019 - 2024. All rights reserved.