自定义工具错误:Command.proto:11:18:“Message2”没有定义

发布于 2024-08-28 12:39:29 字数 547 浏览 3 评论 0原文

我正在使用最新版本的 protobuf-net 与 VS2008 集成。我创建了 2 条消息(Message1 和 Message2),1 条消息位于 1 个原始文件中。当我尝试在 Message1 中引用 Message2 时,代码生成器工具给出错误“Message2”未定义,并且不会生成代码文件。两条消息的包是相同的。
看起来是这样,因为该工具与 VS2008 集成,它希望编译同一 .proto 文件中的所有消息。目前,我必须在 Message1.proto 文件中粘贴一条具有相同名称的空消息,如下所示:

message Message1 {
 optional Message2 message2 = 1;
}

message Message2 {
}

然后稍后从 Message1.cs 中删除 class Message2 的声明。 我是否需要进行任何设置以避免此错误,或者提供空声明是唯一的方法? 或者,如果没有,那么我建议您(Marc Gravell)包含一个像“extern”这样的关键字来告诉编译器该类型的定义在另一个类中可用

I am using the latest version of protobuf-net with VS2008 integration. I have created 2 messages (Message1 and Message2), 1 message in 1 proto file. When I try to reference Message2 in Message1 the code generator tool gives me error "Message2" is not defined and won't generate the code file. The package for both messages is same.
It look like that because of the integration of the tool with VS2008 it expects all the messages in same .proto file to compile. Currently I have to paste an empty message with same name in Message1.proto file, like this:

message Message1 {
 optional Message2 message2 = 1;
}

message Message2 {
}

And then later on remove the declaration of class Message2 from Message1.cs.
Are there any settings that I need to do so to avoid this error, or is providing an empty declaration the only way?
Or if there isn't then I suggest that you (Marc Gravell) include a keyword like "extern" to tell the compiler that the definition of this type is available in another class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空袭的梦i 2024-09-04 12:39:29

我有:

(File1.proto)

import "File2.proto";
message Message1 {
 optional Message2 message2 = 1;
}

(File2.proto)

message Message2 {
}

每个都用自定义工具 (ProtoBufTool) 装饰(在 IDE 中)并且它工作正常。生成两个 .cs 文件,每个文件嵌套在 File*.proto 文件下,每个文件中都包含必要的生成类型。

我错过了什么吗?我猜我可以让第一个文件(单独)从导入的文件中生成类型,但要做到这一点,我实际上需要从头开始编写一个解析器(目前它使用谷歌的 .proto引擎盖下的解析器)。

重新改变语言——这不取决于我;但您只是指(现有的)import 声明吗?

I have:

(File1.proto)

import "File2.proto";
message Message1 {
 optional Message2 message2 = 1;
}

(File2.proto)

message Message2 {
}

Each decorated (in the IDE) with the custom tool (ProtoBufTool) and it is working fine. Two .cs files are generated, one each nested under the File*.proto files, with the necessary generated types in each.

Have I missed something? I guess I could make the first file (alone) generate the types from the imported files, but to do that I'd actually need to write a parser from scratch (at the moment it uses google's .proto parser under the hood).

Re changing the language - that isn't up to me; but do you simply mean the (existing) import declaration?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文