문제

TLDR; devenv appears to build dependencies with whatever config/platform was last selected in the GUI, rather than what /projectconfig says. Ideas?


I have a Visual Studio 2012 solution that builds debug & release, win32 & x64. It has two projects

  • "common" produces a static library
  • "foo" produces a dll, and links with common.lib

Both projects output to $(SolutionDir)$(Configuration)_$(Platform), e.g. myTest/Release_Win32 so I can easily swap between configs.

The project foo depends on common, and when I explicitly build foo in the full GUI it properly builds common first, for whichever configuration/platform I'm currently targetting.

However, If I run the command line

devenv.exe myTest/myTest.sln /project foo /projectconfig "Release|x64" /build

Then it will fail because it can't find common.lib when linking. Indeed, there's no myTest/Release_x64/common.lib, but there IS myTest/Debug_Win32/common.lib. I can verify this is caused by that devenv command, it re-appears after removing all the directories.

It appears devenv is trying to build common as a dependency, but failing to specify the projectconfig and falling back to the default Debug & Win32.

I can work around this by manually building common before attempting to build foo, but I'd prefer it to happen automagically. Has anyone else encountered this, or have a workaround/solution?


Here's a solution that demonstrates the problem, and how I created it:

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

  • created "common" as Static Lib with new solution
  • created "foo" as Console App in that solution
  • added $(OutDir)common.lib as Additional Dependency under Linker/Input for all configurations on foo
  • marked "foo" depends on "common"
  • exited visual studio, saving projects & solution

running devenv myTest/myTest.sln /project foo /projectconfig "Release|x64" /build produces:

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 ==========

If you open Visual Studio, change the platform/config to anything else, and exit (it won't ask to save), then common will build as THAT platform/config.

This happens with both the VS2012 x64 Cross Tools Command Prompt and VS2012 x86 Native Tools Command Prompt.

도움이 되었습니까?

해결책

Confirming Hans Passant's comment, The docs for devenv say:

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

Using MSBuild instead as

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

lets it get the platform & config properly. This Q/A shall serve as a warning to those still using devenv on the command line. Repent & switch!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top