I'm trying to run protobuf's protoc during a dotnet build process with dotnet core 2.1 (this seemed to more or less work with 2.0, but we want to take advantage of 2.1 features). The .csproj file has a stolen snippet to run this:
<!-- https://github.com/protocolbuffers/protobuf/issues/3820#issuecomment-399538660 -->
<PropertyGroup>
<protoc_linux64>tools\linux_x64\protoc</protoc_linux64>
<protoc_linux86>tools\linux_x86\protoc</protoc_linux86>
<protoc_macosx64>tools\macosx_x64\protoc</protoc_macosx64>
<protoc_macosx86>tools\macosx_x86\protoc</protoc_macosx86>
<protoc_windows64>tools\windows_x64\protoc.exe</protoc_windows64>
<protoc_windows86>tools\windows_x86\protoc.exe</protoc_windows86>
</PropertyGroup>
<PropertyGroup Condition=" '$(MSBuildRuntimeType)' == 'Core' or
 ('$(MSBuildVersion)' != '' and
 $([System.Version]::Parse($(MSBuildVersion))) >= $([System.Version]::Parse(15.3))) ">
<protoc Condition="'$([MSBuild]::IsOsPlatform(Linux))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X64'">$(protoc_linux64)</protoc>
<protoc Condition="'$([MSBuild]::IsOsPlatform(Linux))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X86'">$(protoc_linux86)</protoc>
<protoc Condition="'$([MSBuild]::IsOsPlatform(OSX))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X64'">$(protoc_macosx64)</protoc>
<protoc Condition="'$([MSBuild]::IsOsPlatform(OSX))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X86'">$(protoc_macosx86)</protoc>
<protoc Condition="'$([MSBuild]::IsOsPlatform(Windows))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X64'">$(protoc_windows64)</protoc>
<protoc Condition="'$([MSBuild]::IsOsPlatform(Windows))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X86'">$(protoc_windows86)</protoc>
</PropertyGroup>
<Target Name="BuildProto" BeforeTargets="Compile;Restore">
<ItemGroup>
<Protos Include="$(ProjectDir)Protobuf\Protos\*.proto" />
</ItemGroup>
<Message Importance="high" Text="protobuffing" />
<Exec Command="$(NuGetPackageRoot)google.protobuf.tools\3.6.1\$(protoc) --proto_path=$(ProjectDir) --csharp_out=$(ProjectDir)Protobuf\ --csharp_opt=file_extension=.g.cs @(Protos, ' ')" />
</Target>
When this runs, it works. The .g.cs files are generated, everything is great. But if I start with a clean build, and run the build against the solution, then the .g.cs files are not generated. The build obviously fails after that since everything that is generated can't be found.
git clean -dxf < /dev/null ; dotnet build MySolution.sln -m:1
When I search the output for the <Message.. text ("protobuffing"), it's not there. But if I run the dotnet build a second time, then it runs the "protobuffing" right after all the "Restore completed" outputs, and then everything just works. (The reason for the < /dev/null is that I'm running this on Windows where sometimes Visual Studio has stuff locked in the .vs directory, that should be harmless here, so it gets ignored.)
I suppose I could set up the CI build server to run dotnet build twice, but that seems like a hack to me. I'm just looking for a way to get dotnet build under net core 2.1 to run this target before building C# code for this assembly.