0

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:\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

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>

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=Model Person.proto

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

jdphenix
  • 15,022
  • 3
  • 41
  • 74

2 Answers2

0

Try:

<PackageReference Include="Google.Protobuf.Tools" Version="3.10.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
0

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 

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.

Soenhay
  • 3,958
  • 5
  • 34
  • 60