We want to extend our C++ project with the support for proto files. We defined ProjectSchemaDefinitions for ProtoBuf and Visual Studio can recognize such files.
We extended the BeforeBuildGenerateSourcesTargets property to execute protoc compiler when C++ project is generating source code files (see Microsoft.BuildSteps.Targets from VC160 toolset).
Out target is correctly called when we run Rebuild or the vcxproj file is changed. We checked the Inputs and Outputs definitions for the GrpcCompileForCpp target and incremental build detects if proto file changed and GrpcCompileForCpp should be run.
When we use Build Solution only, Visual Studio will immediately return All outputs are up-to-date. and it does not even run the msbuild. This causes issues when we change proto files - they won't be compiled unless we run Rebuild.
Steps to reproduce
Project file
<Project>
<ItemGroup>
<ProtoBuf Include="Server.proto" />
</ItemGroup>
<PropertyGroup>
<!-- Extend the C++ build system with generating gRPC files -->
<BeforeBuildGenerateSourcesTargets>$(BeforeBuildGenerateSourcesTargets);GrpcCompileForCpp</BeforeBuildGenerateSourcesTargets>
<ProtoOutputPath>$(MSBuildThisFileDirectory)</ProtoOutputPath>
</PropertyGroup>
<Target Name="GrpcCompileForCpp" Inputs="@(ProtoBuf)" Outputs="@(ProtoBuf->'%(RootDir)%(Directory)%(Filename).pb.cc')">
<PropertyGroup>
<ProtocCommand>"$(ProtocFullPath)" --cpp_out=$(ProtoOutputPath) --grpc_out=$(ProtoOutputPath) --plugin=protoc-gen-grpc=$(GrpcCppPluginFullPath) -I $(ProtoOutputPath) @(ProtoBuf->'%(FullPath)', ' ')</ProtocCommand>
</PropertyGroup>
<Message Importance="high" Text="$(ProtocCommand)" />
<Exec Command="$(ProtocCommand)" />
</Target>
</Project>
Directory contents:
/
- Server.proto
- ConsoleApplication4.vcxproj
Run Build → Build Solution command from Visual Studio.
Expected behavior
Visual Studio will run msbuild and it will detect the proto file has changed and it will generate new source code.
Actual behavior
Visual Studio reports All outputs are up-to-date.
Environment data
Windows 10 1903
Visual Studio 2019
msbuild 16.2.37902.0
We want to extend our C++ project with the support for proto files. We defined ProjectSchemaDefinitions for ProtoBuf and Visual Studio can recognize such files.
We extended the BeforeBuildGenerateSourcesTargets property to execute protoc compiler when C++ project is generating source code files (see Microsoft.BuildSteps.Targets from VC160 toolset).
Out target is correctly called when we run Rebuild or the vcxproj file is changed. We checked the Inputs and Outputs definitions for the GrpcCompileForCpp target and incremental build detects if proto file changed and GrpcCompileForCpp should be run.
When we use Build Solution only, Visual Studio will immediately return All outputs are up-to-date. and it does not even run the msbuild. This causes issues when we change proto files - they won't be compiled unless we run Rebuild.
Steps to reproduce
Project file
Directory contents:
Run Build → Build Solution command from Visual Studio.
Expected behavior
Visual Studio will run msbuild and it will detect the proto file has changed and it will generate new source code.
Actual behavior
Visual Studio reports All outputs are up-to-date.
Environment data
Windows 10 1903
Visual Studio 2019
msbuild 16.2.37902.0