用< Generator>调用NuGet程序包中的工具,得到意外的“未找到".错误 [英] Invoking tool in a NuGet package with <Generator>, getting unexpected "was not found" error
问题描述
在.NET Core 3.0项目中,我已经安装了 Google.Protobuf.Tools
,
In a .NET Core 3.0 project, I've installed Google.Protobuf.Tools
,
<PackageReference Include="Google.Protobuf" Version="3.10.0" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.10.0" />
所需的 protoc
二进制文件
C:\Users\jdphe>dir %USERPROFILE%\.nuget\packages\google.protobuf.tools\3.10.0\tools\windows_x64
Volume in drive C has no label.
Volume Serial Number is 967E-3D8C
Directory of C:\Users\jdphe\.nuget\packages\google.protobuf.tools\3.10.0\tools\windows_x64
10/14/2019 07:36 PM <DIR> .
10/14/2019 07:36 PM <DIR> ..
10/02/2019 06:08 PM 3,611,120 protoc.exe
1 File(s) 3,611,120 bytes
2 Dir(s) 152,718,581,760 bytes free
但是,当尝试使用csproj中的< Generator>
标签调用 protoc
时,
However, when attempting to invoke protoc
with the <Generator>
tag in my csproj,
<None Update="Person.proto">
<Generator>$(NugetPackageRoot)google.protobuf.tools\3.10.0\tools\windows_x64\protoc.exe --csharp_out=Model Person.proto</Generator>
</None>
未找到生成器"C:\ Users \ jdphe.nuget \ packages \ google.protobuf.tools \ 3.10.0 \ tools \ windows_x64 \ protoc.exe --csharp_out = Model Person.proto".请验证名称.
The generator 'C:\Users\jdphe.nuget\packages\google.protobuf.tools\3.10.0\tools\windows_x64\protoc.exe --csharp_out=Model Person.proto' was not found. Please verify the name.
我已验证该命令可以从命令行的项目文件夹中按预期运行
I've verified that the command runs as expected from the project folder on the command line,
C:\ Users \ jdphe \ source \ repos \ Phenix.Protobufconcat \ Phenix.Protobufconcat>%USERPROFILE%.nuget \ packages \ google.protobuf.tools \ 3.10.0 \ tools \ windows_x64 \ protoc.exe --csharp_out=模型Person.proto
C:\Users\jdphe\source\repos\Phenix.Protobufconcat\Phenix.Protobufconcat> %USERPROFILE%.nuget\packages\google.protobuf.tools\3.10.0\tools\windows_x64\protoc.exe --csharp_out=Model Person.proto
我可能不了解< Generator>
标记应该如何工作,但是我不确定.
I may not be understanding how the <Generator>
tag is supposed to work, but I'm not sure.
推荐答案
根据您的错误消息,找不到Person.proto.尝试使用完整的路径.这可能有效:
Based on your error message, it can't find Person.proto. Try putting the complete path to it. This might work:
$(NugetPackageRoot)google.protobuf.tools\3.10.0\tools\windows_x64\protoc.exe --csharp_out=$(ProjectDir)Model $(ProjectDir)Person.proto
此外,另一种选择(如果您使用的是Visual Studio 2019,则好像使用的是)是使用MSBuild预构建事件.我在此处中列出了一个可行的解决方案.
Also, another option (if you are using Visual Studio 2019 and it seems like you are) is to use a MSBuild pre-build event. I have a working solution listed at the answer here.
这篇关于用< Generator>调用NuGet程序包中的工具,得到意外的“未找到".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!