MSBuild launch multiple times on PostBuildEvent when compiling with -maxcpucount

Francois 1 Reputation point
2021-03-19T17:37:42.55+00:00

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>
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,600 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2021-03-22T06:25:14.793+00:00

    Hi Francois,

    It seems that there are some problems about msbuild tool. We suggest you report it in developer community: https://developercommunity.visualstudio.com/report?space=8&entry=problem

    Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**

    0 comments No comments

  2. Francois 1 Reputation point
    2021-03-23T09:22:42.923+00:00
    0 comments No comments