【问题标题】:Invoking tool in a NuGet package with <Generator>, getting unexpected "was not found" error使用 <Generator> 在 NuGet 包中调用工具,出现意外的“未找到”错误
【发布时间】:2020-09-28 09:00:03
【问题描述】:

在一个 .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 中使用 &lt;Generator&gt; 标记调用 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 =Model Person.proto

我可能不明白&lt;Generator&gt; 标签应该如何工作,但我不确定。

【问题讨论】:

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


    【解决方案1】:

    试试:

    <PackageReference Include="Google.Protobuf.Tools" Version="3.10.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    

    【讨论】:

      【解决方案2】:

      根据您的错误信息,它找不到 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 预构建事件。我在答案here 中列出了一个可行的解决方案。

      【讨论】:

        猜你喜欢
        • 2019-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-19
        • 1970-01-01
        • 1970-01-01
        • 2018-10-22
        • 1970-01-01
        相关资源
        最近更新 更多