[英]Generating c# files from .proto files using protoc on pre build event in VS 2017
I tried to generate c# files from.proto files using protoc
from google.protobuf.tools
nuget package on pre build event in Visual Studio 2017 for all.proto files in particular folder.我尝试使用来自protoc
nuget package 的 protoc 从google.protobuf.tools
文件生成 c# 文件。 I created .net core library project with.proto files.我用 .proto 文件创建了 .net 核心库项目。
Pre-build event command line for for that为此的预构建事件命令行
protoc -I=$(ProjectDir)Messages --csharp_out=$(ProjectDir)Messages $(ProjectDir)*.proto
where protoc
is environment variable for precompiled version of protoc.exe其中protoc
是protoc.exe预编译版本的环境变量
But I got error但我得到了错误
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.
How can I resolve it?我该如何解决?
These links were helpful:这些链接很有帮助:
NugetPackageRoot NugetPackageRoot
The Pre-build command I got to work:我开始工作的预构建命令:
$(NugetPackageRoot)google.protobuf.tools\3.13.0\tools\windows_x64\protoc.exe -I=$(ProjectDir)protos --csharp_out=$(ProjectDir)Messages $(ProjectDir)protos\*.proto
I did not manually install protoc.我没有手动安装protoc。 This command is using the one that came with the Nuget package google.protobuf.tools.此命令使用 Nuget package google.protobuf.tools 附带的命令。
My project structure is as follows:我的项目结构如下:
-Project directory -项目目录
----Messages directory ----留言目录
------myMessages.cs ------myMessages.cs
----protos directory ----protos目录
------myMessages.proto ------myMessages.proto
To answer the specific question:要回答具体问题:
I received the same error and it means that it can't find "protoc".我收到了同样的错误,这意味着它找不到“protoc”。 By using a build command like above, then it will be able to find the protoc exe.通过使用上面的构建命令,它将能够找到 protoc exe。 An obvious downside is that if you update the protobuf packages then you will also need to update the version in MSBuild command.一个明显的缺点是,如果您更新 protobuf 包,那么您还需要在 MSBuild 命令中更新版本。 Maybe someone knows a way to automate that?也许有人知道一种自动化的方法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.