Visual studio vs2012没有';是否将/projectconfig传递给依赖项?
TLDR;devenv似乎使用GUI中最后选择的配置/平台构建依赖关系,而不是/projectconfig所说的。想法Visual studio vs2012没有';是否将/projectconfig传递给依赖项?,visual-studio,visual-studio-2012,dependencies,devenv,Visual Studio,Visual Studio 2012,Dependencies,Devenv,TLDR;devenv似乎使用GUI中最后选择的配置/平台构建依赖关系,而不是/projectconfig所说的。想法 我有一个Visual Studio 2012解决方案,用于构建调试和发布、win32和x64。它有两个项目 “common”生成一个静态库 “foo”生成一个dll,并与common.lib链接 这两个项目都输出到$(SolutionDir)$(Configuration)$(Platform),例如,myTest/Release\u Win32,因此我可以轻松地在配置之
我有一个Visual Studio 2012解决方案,用于构建调试和发布、win32和x64。它有两个项目
- “common”生成一个静态库
- “foo”生成一个dll,并与common.lib链接
myTest/Release\u Win32
,因此我可以轻松地在配置之间切换
项目foo
依赖于common
,当我在完整GUI中显式构建foo
时,它首先正确构建common
,用于我当前针对的任何配置/平台
但是,如果我运行命令行
devenv.exe myTest/myTest.sln/project foo/projectconfig“Release | x64”/build
然后它将失败,因为它在链接时找不到common.lib
。实际上,没有myTest/Release\u x64/common.lib
,但有myTest/Debug\u Win32/common.lib
。我可以验证这是由devenv命令引起的,它在删除所有目录后重新出现
devenv似乎正在尝试将common
构建为依赖项,但未能指定projectconfig并返回默认调试&Win32
在尝试构建foo
之前,我可以通过手动构建common
来解决这个问题,但我更希望它自动发生。是否有其他人遇到过这种情况,或者有解决方法/解决方案
下面是一个解决方案,它演示了问题以及我是如何创建的:
- 使用新的解决方案创建“公共”静态库
- 在该解决方案中将“foo”创建为控制台应用程序
- 添加了$(OutDir)common.lib作为foo上所有配置的链接器/输入下的附加依赖项
- 标记为“foo”取决于“common”
- 已退出visual studio,正在保存项目和解决方案
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跨工具命令提示符
和VS2012 x86本机工具命令提示符
确认Hans Passant的评论时,会发生这种情况,例如:
将MSBuild
改为
MSBuild.exe myTest/myTest.sln /t:foo /p:Configuration=Release;Platform=x64
让它正确地获取平台和配置。此Q/A应作为对仍在命令行上使用
devenv
的人的警告。忏悔&改变 不久前,使用devenv.exe生成已被弃用,请改用MSBuild.exe。
MSBuild.exe myTest/myTest.sln /t:foo /p:Configuration=Release;Platform=x64