简体   繁体   中英

MSBuild deletes one lib file, breaking the build. Visual Studio works fine

I have project dependencies like this:

Main -> A, Common
A -> B, Common

with the build order:

Common
B
A
Main

The solution builds fine in Visual Studio 2019. But in MSBuild, it builds Common.lib , B.lib , A.lib ... then deletes Common.lib , before trying (and failing) to build Main.exe .

I've tried changing the output dir of Common.lib , but every time MSBuild will build it in the new location, then delete it after A.lib is built. It doesn't delete A.lib or B.lib , even when they're in the same dir as Common.lib . I also have another solution with a different Main project with the same dependencies ( A , B and Common ), but MSBuild works fine on that.

Any ideas where to start troubleshooting this?

All projects are in C++ with MFC in a static library, using multibyte character set (the solution was upgraded from VC2005). I'm running MSBuild from command line (cmd.exe). Version numbers:

Visual Studio 16.8.5 
MSBuild 16.8.3.61104

Update:

The build log using -verbosity:diag as @dxiv suggested now gives this build hierarchy at the end. (I've renamed the projects to match the names above)

============================== Build Hierarchy (IDs represent configurations) =====================================================
Id                  : Exclusive Time   Total Time   Path (Targets)
-----------------------------------------------------------------------------------------------------------------------------------
0                   : 0.429s           105.369s     D:\releases\temp_src\Main.sln (rebuild) 
. 1                 : 0.270s           104.941s     D:\releases\temp_src\Main.vcxproj.metaproj (Rebuild) 
| | 2               : 6.218s           31.257s      D:\releases\temp_src\A\A.vcxproj (Rebuild) 
| | | 3             : 1.600s           1.600s       D:\releases\temp_src\B\B.vcxproj (Clean) 
| | | 4             : 0.764s           0.764s       D:\releases\temp_src\Common\Common.vcxproj (Clean) 
| | | 5             : 2.184s           2.184s       D:\releases\temp_src\B\B.vcxproj () 
| | | 6             : 2.507s           2.507s       D:\releases\temp_src\Common\Common.vcxproj () 
| | | 7             : 0.536s           0.536s       D:\releases\temp_src\B\B.vcxproj (GetNativeManifest) 
| | | 8             : 0.643s           0.643s       D:\releases\temp_src\Common\Common.vcxproj (GetNativeManifest) 
| | | 9             : 0.585s           0.585s       D:\releases\temp_src\B\B.vcxproj (GetProjectInfoForReference) 
| | | 10            : 0.668s           0.668s       D:\releases\temp_src\Common\Common.vcxproj (GetProjectInfoForReference) 
| | . 11            : 0.549s           0.549s       D:\releases\temp_src\Common\Common.vcxproj (GetCopyToOutputDirectoryItems) 
| . 12              : 5.923s           10.062s      D:\releases\temp_src\Main.vcxproj (Rebuild) 
| | | 13            : 0.696s           0.696s       D:\releases\temp_src\Common\Common.vcxproj (Clean) 
| | | 14            : 1.845s           1.845s       D:\releases\temp_src\A\A.vcxproj (GetNativeManifest) 
| | | 15            : 0.969s           0.969s       D:\releases\temp_src\A\A.vcxproj (GetProjectInfoForReference) 
| | . 16            : 0.629s           0.629s       D:\releases\temp_src\Common\Common.vcxproj (GetProjectInfoForReference) 

ID 13 shows Common.vcxproj being cleaned just as Main begins the rebuild; this seems like the action that deleted the Common.lib . What could cause it to perform this clean?

You should note the build has a order: Common-->B-->A-->Main

If Main project has an error, it will not stop the A and B project's build because they has no error.

Also , if the bottom project Common has an error, when it will break the whole rebuild process, delete A and Main project output files.

Also , when you try tp change the outdir of the four projects, you should right-click on every project Properties --> General --> Output Directories or just modify every outdir properties of vcxproj files. When you rebuild it, it will delete the old location output files and then build again.

In my side, when I run msbuild xxx\xxx.sln -t:clean , it remove the all old previous output files.

If not, I think there are some problems of your current projects. Please try the following steps:

1) remove any project references of these projects and then right-click on the Reference of related projects-->Re-add project Reference

2) re-modify the outdir property under each vcxproj files and then make the value the same.

3) delete .vs hidden folder and any output folders of these four projects.

4) Instead, run msbuild xxx\xxx.sln -t:rebuild to build your solution.

Besides , if my answer did not meet your requirements, please make your issue more clear and use more pics,.... to describe your issue in more detail.

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