Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have different Project Dependencies for each Project Configuration?

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.

like image 621
k0dek0mmand0 Avatar asked Oct 05 '09 09:10

k0dek0mmand0


2 Answers

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

like image 169
Daniel Avatar answered Nov 15 '22 09:11

Daniel


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.

like image 25
Jan Hudec Avatar answered Nov 15 '22 09:11

Jan Hudec