【问题标题】:vs2012 doesn't pass /projectconfig to dependencies?vs2012 不会将 /projectconfig 传递给依赖项?
【发布时间】:2013-11-29 03:22:45
【问题描述】:

TLDR; devenv 似乎使用 GUI 中最后选择的任何配置/平台来构建依赖关系,而不是 /projectconfig 所说的。想法?


我有一个构建调试和发布、win32 和 x64 的 Visual Studio 2012 解决方案。它有两个项目
  • “common”生成静态库
  • "foo" 生成一个 dll,并与 common.lib 链接

两个项目都输出到 $(SolutionDir)$(Configuration)_$(Platform),例如myTest/Release_Win32 这样我就可以轻松地在配置之间进行切换。

项目foo 依赖于common,当我在完整的GUI 中显式构建foo 时,它首先正确构建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。

我可以通过在尝试构建 foo 之前手动构建 common 来解决此问题,但我希望它自动发生。有没有其他人遇到过这种情况,或者有解决方法/解决方案?


这是一个演示问题的解决方案,以及我是如何创建它的:

http://beanalby.net/stackExchange/vsDepends.zip

  • 使用新解决方案创建了“common”作为静态库
  • 在该解决方案中创建了“foo”作为控制台应用程序
  • 在 foo 上的所有配置的链接器/输入下添加了 $(OutDir)common.lib 作为附加依赖项
  • 标记为“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 Cross Tools Command PromptVS2012 x86 Native Tools Command Prompt 都会出现这种情况。

【问题讨论】:

  • 使用 devenv.exe 构建已被弃用,请改用 MSBuild.exe。

标签: visual-studio visual-studio-2012 dependencies devenv


【解决方案1】:

确认 Hans Passant 的评论,docs for devenv 说:

Note
For build-related tasks, it is now recommended that you use MSBuild
instead of devenv. For more information, see MSBuild Command-Line Reference.

使用MSBuild 代替

MSBuild.exe myTest/myTest.sln /t:foo /p:Configuration=Release;Platform=x64

让它正确获取平台和配置。此 Q/A 应作为对仍在命令行上使用 devenv 的人的警告。忏悔并转换!

【讨论】:

    猜你喜欢
    • 2016-10-08
    • 1970-01-01
    • 2016-05-30
    • 2021-04-22
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    相关资源
    最近更新 更多