【问题标题】:Generating c# files from .proto files using protoc on pre build event in VS 2017在 VS 2017 的预构建事件中使用 protoc 从 .proto 文件生成 c# 文件
【发布时间】:2019-10-03 14:29:22
【问题描述】:

我尝试在 Visual Studio 2017 中的预构建事件中使用 protoc 中的 protoc 从 .proto 文件生成特定文件夹中所有 .proto 文件的 nuget 文件。我使用 .proto 文件创建了 .net 核心库项目。

为此的预构建事件命令行

protoc -I=$(ProjectDir)Messages --csharp_out=$(ProjectDir)Messages $(ProjectDir)*.proto

protocprotoc.exe

预编译版本的环境变量

但我得到了错误

 error MSB3073: The command "protoc -I=C:\Projects\TecAlliance.Core.Messages\TecAlliance.Core.Messages\Messages --csharp_out=C:\Projects\TecAlliance.Core.Messages\TecAlliance.Core.Messages\Messages C:\Projects\TecAlliance.Core.Messages\TecAlliance.Core.Messages\GpsCoodinates.proto" exited with code 9009.
1>Done building project "TecAlliance.Core.Messages.csproj" -- FAILED.

我该如何解决?

【问题讨论】:

  • 另外 9009 表示 file not found
  • 您找到解决方案了吗?我在 VS2019 中遇到了类似的问题,Nuget 包 Google.Protobuf 和 Google.Protobuf.Tools。我正在尝试在 .Net 标准库中使用它们。

标签: c# visual-studio .net-core protocol-buffers


【解决方案1】:

这些链接很有帮助:

NugetPackageRoot

MSBuild Prebuild

我开始工作的预构建命令:

$(NugetPackageRoot)google.protobuf.tools\3.13.0\tools\windows_x64\protoc.exe -I=$(ProjectDir)protos --csharp_out=$(ProjectDir)Messages $(ProjectDir)protos\*.proto

我没有手动安装 protoc。此命令使用 Nuget 包 google.protobuf.tools 附带的命令。

我的项目结构如下:

-项目目录

----消息目录

------myMessages.cs

----protos目录

------myMessages.proto

回答具体问题:

我收到了同样的错误,这意味着它找不到“protoc”。通过使用上面的构建命令,它将能够找到 protoc exe。一个明显的缺点是,如果您更新 protobuf 包,那么您还需要在 MSBuild 命令中更新版本。也许有人知道自动化的方法?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-25
    • 2022-08-02
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多