[英]Invoking tool in a NuGet package with <Generator>, getting unexpected “was not found” error
在 .NET Core 3.0 项目中,我安装了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
时,
<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”。 请验证名称。
我已经验证该命令在命令行的项目文件夹中按预期运行,
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=模型人.proto
我可能不理解<Generator>
标签应该如何工作,但我不确定。
尝试:
<PackageReference Include="Google.Protobuf.Tools" Version="3.10.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
根据您的错误消息,它找不到 Person.proto。 试着把它的完整路径。 这可能有效:
$(NugetPackageRoot)google.protobuf.tools\3.10.0\tools\windows_x64\protoc.exe --csharp_out=$(ProjectDir)Model $(ProjectDir)Person.proto
此外,另一种选择(如果您使用的是 Visual Studio 2019 并且看起来像)是使用 MSBuild 预构建事件。 我在此处的答案中列出了一个可行的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.