TLDR;devenv 似乎使用 GUI 中最后选择的任何配置/平台来构建依赖关系,而不是 /projectconfig 所说的。想法?
我有一个构建调试和发布、win32 和 x64 的 Visual Studio 2012 解决方案。它有两个项目
- "common" 生成一个静态库
- "foo" 生成一个 dll,并与 common.lib 链接
两个项目都输出到 $(SolutionDir)$(Configuration)_$(Platform),例如,myTest/Release_Win32
这样我就可以轻松地在配置之间进行交换。
该项目foo
依赖于common
,当我foo
在完整的 GUI 中显式构建时,它会正确构建common
,适用于我当前定位的任何配置/平台。
但是,如果我运行命令行
devenv.exe myTest/myTest.sln /project foo /projectconfig "Release|x64" /build
common.lib
然后它会失败,因为它在链接时找不到。确实,没有myTest/Release_x64/common.lib
,但有myTest/Debug_Win32/common.lib
。我可以验证这是由 devenv 命令引起的,它在删除所有目录后重新出现。
看来 devenv 正在尝试构建common
为依赖项,但未能指定 projectconfig 并回退到默认的 Debug & Win32。
common
我可以通过在尝试构建之前手动构建来解决这个问题foo
,但我更希望它自动发生。有没有其他人遇到过这种情况,或者有解决方法/解决方案?
这是一个演示问题的解决方案,以及我是如何创建它的:
http://beanalby.net/stackExchange/vsDepends.zip
- 用新的解决方案创建了“common”作为静态库
- 在该解决方案中创建“foo”作为控制台应用程序
- 在 foo 上的所有配置的链接器/输入下添加 $(OutDir)common.lib 作为附加依赖项
- 标记为“foo”取决于“common”
- 退出视觉工作室,保存项目和解决方案
运行devenv myTest/myTest.sln /project foo /projectconfig "Release|x64" /build
产生:
C:\Users\jason\Desktop>devenv myTest/myTest.sln /project foo /projectconfig "Release|x64" /build
Microsoft (R) Microsoft Visual Studio 2012 Version 11.0.60610.1.
Copyright (C) Microsoft Corp. All rights reserved.
1>------ Build started: Project: common, Configuration: Debug Win32 ------
1>Build started 11/15/2013 13:15:22.
1>PrepareForBuild:
1> Creating directory "C:\Users\jason\Desktop\myTest\Debug\".
1>InitializeBuildStatus:
1> Creating "Debug\common.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> stdafx.cpp
1>Lib:
1> common.vcxproj -> C:\Users\jason\Desktop\myTest\Debug\common.lib
1>FinalizeBuildStatus:
1> Deleting file "Debug\common.unsuccessfulbuild".
1> Touching "Debug\common.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.52
2>------ Build started: Project: foo, Configuration: Release x64 ------
2>Build started 11/15/2013 13:15:22.
2>PrepareForBuild:
2> Creating directory "C:\Users\jason\Desktop\myTest\x64\Release\".
2>InitializeBuildStatus:
2> Creating "x64\Release\foo.unsuccessfulbuild" because "AlwaysCreate" was specified.
2>ClCompile:
2> stdafx.cpp
2> foo.cpp
2>LINK : fatal error LNK1181: cannot open input file 'C:\Users\jason\Desktop\myTest\x64\Release\comm
on.lib'
2>
2>Build FAILED.
2>
2>Time Elapsed 00:00:00.56
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
如果您打开 Visual Studio,将平台/配置更改为其他任何内容,然后退出(它不会要求保存),那么common
将构建为那个平台/配置。
VS2012 x64 Cross Tools Command Prompt
和都会发生这种情况VS2012 x86 Native Tools Command Prompt
。