Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio Can';t链接不同项目上的原型文件_Visual Studio_Grpc - Fatal编程技术网

Visual studio Can';t链接不同项目上的原型文件

Visual studio Can';t链接不同项目上的原型文件,visual-studio,grpc,Visual Studio,Grpc,可以构建Grpc服务器项目 但要建立Grpc客户端项目 错误“未找到文件”duration.proto和timestamp.proto 有办法解决吗?谢谢 GRPCS服务项目 文件路径 Protos\google\duration.proto Protos\google\timestamp.proto Protos\greet.proto GrpcService.csproj GrpcClient项目 GrpcService.csproj <ItemGroup> <Prot

可以构建Grpc服务器项目

但要建立Grpc客户端项目

错误“未找到文件”duration.proto和timestamp.proto

有办法解决吗?谢谢

GRPCS服务项目 文件路径 Protos\google\duration.proto

Protos\google\timestamp.proto

Protos\greet.proto

GrpcService.csproj GrpcClient项目 GrpcService.csproj

<ItemGroup>
  <Protobuf Include="..\GrpcService\Protos\google\duration.proto">
    <Link>Protos\google\duration.proto</Link>
  </Protobuf>
  <Protobuf Include="..\GrpcService\Protos\google\timestamp.proto">
    <Link>Protos\google\timestamp.proto</Link>
  </Protobuf>
  <Protobuf Include="..\GrpcService\Protos\greet.proto" GrpcServices="Clinet">
    <Link>Protos\greet.proto</Link>
  </Protobuf>
</ItemGroup>

Protos\google\duration.proto
Protos\google\timestamp.proto
Protos\greet.proto

复制文件tp Grpc client project可以解决这个问题,但是它会失去链接文件的功能

如果包含“众所周知的proto”,例如duration.proto和timestamp.proto,则不需要执行任何操作。1.为这些protos生成的代码是Google.Protobuf运行时的一部分。2.为包含“google/duration.proto”等文件的.proto生成代码时,duration.proto(以及其他众所周知的proto)由Grpc.Tools包自动提供(这些proto实际上捆绑在该nuget pkg中)。通常,最有用的是在msbuild中启用调试日志,并检查Grpc.Tools执行的protoc命令
syntax = "proto3";

option csharp_namespace = "Grpc.Base";

import "Protos/google/duration.proto";  
import "Protos/google/timestamp.proto";

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;
    google.protobuf.Timestamp start = 2;
    google.protobuf.Duration duration = 3;
}
<ItemGroup>
  <Protobuf Include="..\GrpcService\Protos\google\duration.proto">
    <Link>Protos\google\duration.proto</Link>
  </Protobuf>
  <Protobuf Include="..\GrpcService\Protos\google\timestamp.proto">
    <Link>Protos\google\timestamp.proto</Link>
  </Protobuf>
  <Protobuf Include="..\GrpcService\Protos\greet.proto" GrpcServices="Clinet">
    <Link>Protos\greet.proto</Link>
  </Protobuf>
</ItemGroup>