使用 <Generator> 调用 NuGet 包中的工具,意外“未找到"错误 [英] Invoking tool in a NuGet package with <Generator>, getting unexpected "was not found" error

查看:19
本文介绍了使用 <Generator> 调用 NuGet 包中的工具,意外“未找到"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .NET Core 3.0 项目中,我安装了 Google.Protobuf.Tools

<PackageReference Include="Google.Protobuf.Tools" Version="3.10.0"/>

protoc 二进制文件是预期的,

C:Usersjdphe>dir %USERPROFILE%.nugetpackagesgoogle.protobuf.tools3.10.0	oolswindows_x64驱动器 C 中的卷没有标签.卷序列号为 967E-3D8CC:Usersjdphe.nugetpackagesgoogle.protobuf.tools3.10.0	oolswindows_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.exe1 个文件 3,611,120 字节2 目录 152,718,581,760 字节空闲

但是,当尝试在我的 csproj 中使用 <Generator> 标记调用 protoc 时,

<Generator>$(NugetPackageRoot)google.protobuf.tools3.10.0	oolswindows_x64protoc.exe --csharp_out=Model Person.proto</Generator></无>

<块引用>

未找到生成器C:Usersjdphe.nugetpackagesgoogle.protobuf.tools3.10.0 oolswindows_x64protoc.exe --csharp_out=Model Person.proto".请验证名称.

我已验证该命令在命令行上的项目文件夹中按预期运行,

<块引用>

C:Usersjdphesource eposPhenix.ProtobufconcatPhenix.Protobufconcat> %USERPROFILE%.nugetpackagesgoogle.protobuf.tools3.10.0 oolswindows_x64protoc.exe --csharp_out=Model Person.proto

我可能不明白 标签应该如何工作,但我不确定.

解决方案

根据您的错误消息,它找不到 Person.proto.尝试将完整的路径放到它.这可能有效:

$(NugetPackageRoot)google.protobuf.tools3.10.0	oolswindows_x64protoc.exe --csharp_out=$(ProjectDir)Model $(ProjectDir)Person.proto

此外,另一种选择(如果您使用的是 Visual Studio 2019 并且看起来像您一样)是使用 MSBuild 预构建事件.我在此处的答案中列出了一个可行的解决方案.

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" />

The protoc binary is where it is expected,

C:Usersjdphe>dir %USERPROFILE%.nugetpackagesgoogle.protobuf.tools3.10.0	oolswindows_x64
 Volume in drive C has no label.
 Volume Serial Number is 967E-3D8C

 Directory of C:Usersjdphe.nugetpackagesgoogle.protobuf.tools3.10.0	oolswindows_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

However, when attempting to invoke protoc with the <Generator> tag in my csproj,

<None Update="Person.proto">
  <Generator>$(NugetPackageRoot)google.protobuf.tools3.10.0	oolswindows_x64protoc.exe --csharp_out=Model Person.proto</Generator>
</None>

The generator 'C:Usersjdphe.nugetpackagesgoogle.protobuf.tools3.10.0 oolswindows_x64protoc.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:Usersjdphesource eposPhenix.ProtobufconcatPhenix.Protobufconcat> %USERPROFILE%.nugetpackagesgoogle.protobuf.tools3.10.0 oolswindows_x64protoc.exe --csharp_out=Model Person.proto

I may not be understanding how the <Generator> tag is supposed to work, but I'm not sure.

解决方案

Based on your error message, it can't find Person.proto. Try putting the complete path to it. This might work:

$(NugetPackageRoot)google.protobuf.tools3.10.0	oolswindows_x64protoc.exe --csharp_out=$(ProjectDir)Model $(ProjectDir)Person.proto 

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.

这篇关于使用 &lt;Generator&gt; 调用 NuGet 包中的工具,意外“未找到"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆