导入 "google/protobuf/timestamp.proto" 未找到或有错误

Import "google/protobuf/timestamp.proto" was not found or had errors

我正在尝试使用时间戳并将其导入到 protobuf 消息中 -

import "google/protobuf/timestamp.proto";

message TriggerDataMsg {
    google.protobuf.Timestamp start_time = 1;
    google.protobuf.Timestamp end_time = 2;
    google.protobuf.Timestamp next_fire_time = 3;
    google.protobuf.Timestamp previous_fire_time = 4;
    sint32 priority = 13;
}

当尝试使用 protoc 编译器编译生成 Java 类 时,失败并出现以下错误 -

 [echo] compiling proto sources...
 [exec] google/protobuf/timestamp.proto:35:8: Option "csharp_namespace" unknown.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:24:5: "google.protobuf.Timestamp" is not defined.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:25:5: "google.protobuf.Timestamp" is not defined.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:26:5: "google.protobuf.Timestamp" is not defined.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:27:5: "google.protobuf.Timestamp" is not defined.

我不确定为什么它会检查“csharp_namespace”,即使我正在生成 Java 类。 我可以尝试消除此错误的任何解决方法吗?

如果您希望 protoc 自动导入某些内容,它需要位于您的 protoc 二进制文件旁边的 /include 文件夹中。

Reference

If I remember correctly, protoc looks for includes relative to the protoc binary. So if protoc is in /usr/local/bin, then it will look in /usr/local/include.

这对我来说非常有效 Windows 来解决:

Import "google/protobuf/wrappers.proto" was not found or had errors.