MSBuild 删除了一个 lib 文件,破坏了构建。 Visual Studio 工作正常

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

我有这样的项目依赖:

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

构建顺序:

Common
B
A
Main

该解决方案在 Visual Studio 2019 中构建良好。但在 MSBuild 中,它构建 Common.libB.libA.lib ... 然后删除 Common.lib ,在尝试(但失败)构建 Main.exe.

之前

我试过更改 Common.lib 的输出目录,但每次 MSBuild 都会在新位置构建它,然后在构建 A.lib 后将其删除。它不会删除 A.libB.lib,即使它们与 Common.lib 位于同一目录中。我还有另一个解决方案,它具有具有相同依赖项(ABCommon)的不同主项目,但 MSBuild 在这方面工作正常。

知道从哪里开始解决这个问题吗?

所有项目都是C++,静态库中有MFC,使用多字节字符集(解决方案是从VC2005升级而来)。我是来自命令行的 运行 MSBuild (cmd.exe)。版本号:

Visual Studio 16.8.5 
MSBuild 16.8.3.61104

更新:

按照@dxiv 的建议使用-verbosity:diag 的构建日志现在在末尾给出了这个构建层次结构。 (我已重命名项目以匹配上面的名称)

============================== 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 显示 Common.vcxprojMain 开始重建时正在清理;这似乎是删除 Common.lib 的操作。是什么导致它执行此清理操作?

您应该注意到构建有一个顺序:Common-->B-->A-->Main

如果Main项目出错,不会停止AB项目的构建,因为它们没有错误。

,如果底层工程Common有错误,会打断整个rebuild过程,删除AMain 项目输出文件。

还有,当你尝试tp改变四个项目的outdir时,你应该在每个项目上右击Properties-- >General-->Output Directories 或者只修改 vcxproj 文件的每个 outdir 属性。当您重建它时,它会删除旧的位置输出文件,然后重新构建。

在我这边,当我 运行 msbuild xxx\xxx.sln -t:clean 时,它会删除所有旧的以前的输出文件。

如果不是,我觉得你现在的项目有问题。请尝试以下步骤:

1)删除这些项目的任何项目引用然后右击相关项目的引用-->重新-添加项目引用

2)重新修改每个vcxproj文件下的outdir属性然后使值一致

3)删除.vs这四个项目的隐藏文件夹和任何输出文件夹。

4) 相反,运行 msbuild xxx\xxx.sln -t:rebuild 来构建您的解决方案。

此外,如果我的回答没有达到您的要求,请把您的问题说清楚,多用图片,....更详细的描述您的问题。