How to have different Project Dependencies for each Project Configuration?
Asked Answered
G

6

7

I would like to have different Project Dependencies depending on which Project Configuration I'm currently building.

For example, I don't want to build and link SomeTestLib.vcproj in Release configuration, but I'd like to build and link to it in Debug.

One solution, that sorta works, is to use conditional compilation macros:

#ifdef DEBUG  
#pragma comment( lib, "SomeTestLib" )  
#endif

But in this case, the debugger and IntelliSense don't work for SomeTestLib.
Is there a .sln or .vcproj hack that I could use?
Thanks.

Guardsman answered 5/10, 2009 at 9:34 Comment(0)
W
7

After searching Google for days, I finally gave up on finding a solution to this problem and blew a VS developer, who gave me the workaround for this problem (actually, I tried a bajillion different things on my own to find this).

Apparently, the IDE isn't smart enough to figure out that you've disabled building for a particular library under a given configuration and to not add that project's output to the linker command line for projects that depend on it. I'm sure that you are aware of this.

However, since it is just pasting the output line from the library project into the command line of the dependent project, setting the output line to " " will result in NOTHING being added to the linker command line on dependent projects!

Hopefully, this problem will be remedied in Visual Studio in the future. I remain optimistic, because it is my favorite IDE, and I am always impressed by the features it supports. However, some of the VS help threads that I've seen say that this bug is "by design", so maybe they won't fix it. It seems easy enough to do, though.

Anyways, to summarize:

  • Right-Click on your library project in the Solution Explorer and Click "Properties".
  • Switch to the "Configuration/Platform" pair that your library project does not build for.
  • Select "Configuration Properties -> Librarian -> General".
  • For "Output File", type " " (that is open parens, space, close parens).
  • Click OK.

Please note that this workaround will give you errors if you Build or Clean the disabled library project. If you just build your solution, it will be skipped on disabled configurations, so you won't get errors.

Hope this helps!

Daniel

Wilbanks answered 19/1, 2010 at 16:22 Comment(1)
Thanks, this is great! Another thing: If the dependency you're linking happens to be a .dll, you can also set the name of the Import Library to " " and it'll be ignored. This option is under Linker->Advanced->Import Library.Guardsman
M
3

It's possible to turn off the Linker/General/Link library dependencies property in the dependent project and put the library in linker inputs in relevant configurations.

It makes the project references less useful, but is workable.

Mages answered 3/11, 2009 at 14:12 Comment(0)
K
1

Set the configuration type to Utility instead of application/library in the project properties -> General..

Kadi answered 21/11, 2011 at 13:11 Comment(0)
R
0

In visual studio, each build configuration keeps its own list of properties for your project. Just add your lib to whichever build configuration you want. Just don't add to "All Configurations"

Ravenna answered 5/10, 2009 at 9:37 Comment(1)
I'm actually asking about a project that is a part of the solution, not an external lib. I'm aware of the option you're suggesting. What I'd like to achieve is to mark a project dependency inactive in certain solution configurations.Guardsman
E
0

Right click your solution and select properties. Solution property page will show up..

In right page select Configuration Properties >>> Configuration

Here you can select the build configuration for Debug, Release and All build type by checking the check box labeled as Build.

Electrodynamics answered 5/10, 2009 at 9:38 Comment(3)
If I understand correctly, unchecking a project here will prevent it from being built. But if this unchecked project is marked as a Project Dependency, the linker will complain (SomeTestLib.lib can not be found.)Guardsman
Not if it's already built and the assembly is present in the same directory. Since when you built a project all its dependencies other then those installed in GAC is copied into the private folder of that assembly. However since it's dependent on other assembly and a change is made in the source of that assembly it'll built all the dependencies first.Electrodynamics
OK, but I don't even want to build SomeTestLib in the Release configuration, that's the whole point. :)Guardsman
I
0

In the main project, go to Configuration Properties -> Linker -> Input, in the section titled "Ignore Specific Library" add the lib you want eignored, e.g.: .lib. Do this again for the other configuration, except ignore a different lib/dll.

Finally, if you don't want each project building for both configurations, right click the Solution -> Project Dependencies -> [Select main / top-level project] -> Uncheck the project you don't want built / ignored.

This method has the advantage that you can still manually build each project if desired, but can switch configurations and only build/use the lib/dll you want.

Irrespective answered 12/6, 2012 at 4:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.