Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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
C# 如何在proto file import语句中使用相对路径?_C#_Protobuf Net - Fatal编程技术网

C# 如何在proto file import语句中使用相对路径?

C# 如何在proto file import语句中使用相对路径?,c#,protobuf-net,C#,Protobuf Net,我正在使用ProtoBufTool自定义工具为protobuf net从.proto文件生成C#类。到目前为止,我无法使proto文件中的import语句使用相对路径。以下是我的情况: 我的项目中有两个原型文件,如下所示: User.proto: package Models; message User { required int32 ID = 1; required string Username = 2; // etc... } UserSearch.prot

我正在使用ProtoBufTool自定义工具为protobuf net从.proto文件生成C#类。到目前为止,我无法使proto文件中的
import
语句使用相对路径。以下是我的情况:

我的项目中有两个原型文件,如下所示:

User.proto:

package Models;

message User {
    required int32 ID = 1;
    required string Username = 2;
    // etc...
}
UserSearch.proto:

package Models.Messages;

import "../User.proto";

message UserSearchRequest {
    optional string Query = 1;
    optional int32 Limit = 2;
    optional int32 Offset = 3;
}

message UserSearchResult {
    required int32 NumResults = 1;
    required int32 NumReturned = 2;
    repeated User Users = 3;
}
User.cs文件生成良好,但在UserSearch文件上失败。这是我在错误列表窗口中看到的

  • 自定义工具错误:../User.proto:未找到文件
  • 自定义工具错误:UserSearch.proto:Import../User.proto未找到或有错误
  • 自定义工具错误:UserSearch.proto:22:18:未定义“用户”
作为记录,我尝试使用
\\
而不是
/
,得到了相同的结果。另外,如果两个proto文件位于同一目录中,并且我删除了
。/
,import语句也可以正常工作,但这不是我想要排列文件的方式


我如何才能在import语句中获得相对路径?

简短回答-我必须知道在与
protoc
(谷歌的.proto解析器)交谈时,工具及其使用的路径存在缺陷。我必须看一下并修复它

更尴尬的回答如果您不介意使用命令行工具,您可以使用google的proto将.proto编译成二进制,使用
--descriptor\u set\u out={file}
,使用您选择的任何
--proto\u路径
选项(到目前为止,这纯粹是google工具);然后,您可以将编译后的描述符集作为输入传递到
protogen
(它处理任何一种格式)


这对于脚本化的构建来说是可以的,但是您不想手动完成它!我会试着看看工具有什么问题。已添加到列表中。

如果您能修复此错误,我将不胜感激!很好知道(关于原生质接受任何一种格式)。也许我可以利用这一点。但是使用VS工具对我们的开发工作流程会更好。我和Chris有同样的问题,但是在使用
protogen.exe
命令行工具时。我一直收到“Some.proto:未找到文件”错误。用
protoc
编译成一个中间二进制文件,然后将该文件输入到
protogen.exe
中,成功了。@Marc gravel,这个问题解决了吗?