When I try to compile my big solution (100 projects) with MSBuild, I have an error with PostBuildEvent.
I have a very base project where most of other project add depend on. In this project, I have a simple PostBuildEvent which modify the Dll file by adding a "custom signature".
When I run MSBuild with parallel option -maxcpucount, in have this error.
18>PostBuildEvent:
Impossible to open : D:\BuildAgent9\work\b63dd3bbf6a8743c\exe\Debug_x64\DllToSigned.dll
18>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073: The command ""D:\BuildAgent9\work\b63dd3bbf6a8743c\CreateSignature.exe" "D:\BuildAgent9\work\b63dd3bbf6a8743c\exe\Debug_x64\DllToSigned.dll"
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073: :VCEnd" exited with code 1.
My tool, "CreateSignature.exe" print error "Impossible to open : ...", because the file is already open.
The project has already been linked and finished.
Checking in the MSBuild log file, this PostBuildEvent is call about 40 times (for 100 projects to compile). Other project which has a dependency on it, seem to re-ask to execute the PostBuildEvent. Which lead to problem because only one could open the dll file in write access...
Of course, I really need to compile in Parallel, else it takes twice the time to compile the solution.
How to modify the vcxprj in order to have this PostBuildEvent execute only once.
Note that I used the project reference for dependencies between project. Like this:
<ProjectReference Include="..\..\DllToSigned.vcxproj">
<Project>{...}</Project>
<Private>false</Private>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>