简体   繁体   中英

Is it possible to force MSBuild to Only Build A Project Once, Regardless of Properties?

I am currently migrating a large solution from the old csproj file format to the new csproj format. I am doing this a few projects at a time, so I have a mixed environment with some projects using the old project file format and some projects using the new project file format.

I have started to notice some builds failing because files are in use. My theory (based on this answer ) is that MSBuild is building some projects twice because the properties are different (ie the new project file format specify the TargetFramework property while old projects do not).

The projects that seem to have concurrency issues are projects that are referenced by other projects, where the referencing projects are split between the project file formats.

The command I am using to build the project is:

msbuild.exe /maxcpucount:6 /property:Configuration=Debug;Platform=x64 /t:Rebuild my.sln

Is there a way to instruct MSBuild to only build a given project once (regardless of properties) until I am able to convert all of the projects in the solution over to the new project file format?

Note that building single threaded does correct the concurrency issues, but that significantly slows down the build and the projects are still built multiple times.

This is a bug in MSBuild when referencing C++ CLI projects from multi-targeting projects. It appears they are putting in a fix to address this.

To work around the bug, the property can be removed from the reference using the GlobalPropertiesToRemove attribute:

<ProjectReference Include="..\B.CppCLILibrary\B.CppCLILibrary.vcxproj" GlobalPropertiesToRemove="TargetFramework" />

Only you could have correctly solved this since we do not have access to your code. But generally MSBuild and all build systems operate under the rule that a build 'target' is only processed once. No matter how many projects refer to it.

A build system should provide language for the user to specify dependencies between different 'targets'. And then it is up to the build system to figure out in which order to build these things in. (ie called a topological sort). Beginning or starting with making the most independent targets all the way to the least independent target.

If something is getting built twice it could be: 1. A bug in the build system. 2. The user forcing the project to build twice.

Anyways glad you got it sorted out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM