Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing different assemblies in different configurations

Before asking, I read this and this threads. No help there.

I am using Visual Studio 2003 (this is mandated by my employer) but I guess answers to later versions of VS might also be useful.

So, imagine I have two .Net projects: A - which is a class library and B - which is an application. In B I click Add Reference, go to the Projects tab and choose A. In this scenario the debug version of B will reference the debug version of A, and the release version of B will use the release version of A. Now imagine that instead of project A I just have two assemblies - aD.dll and a.dll. I don't have any project that creates these. What I want to do is enforce that Debug version of B reference aD.dll, and the release version of B reference a.dll
Question 1: How do I do this?

When I want to reference some dll, I go to add reference -> Browse and browse my dll. But I need to specify not the full path, but the relative path.
Question 2: How do I do this?

This is an emergency, thanks in advance :)

like image 629
Armen Tsirunyan Avatar asked Nov 05 '10 10:11

Armen Tsirunyan


1 Answers

You can't do this through the IDE, but you can do it by hacking the .csproj file by hand:

If you've already got a reference to, say, a.dll:

<Reference Include="a">...</Reference>

...then try a pair of conditions as follows:

<Reference Condition="'$(Configuration)' == 'Release'" Include="a">...</Reference>
<Reference Condition="'$(Configuration)' == 'Debug'" Include="aD">...</Reference>

Edit: Here's an explanation of what you can put inside a <Reference> element: http://msdn.microsoft.com/en-us/library/bb629388.aspx

like image 112
Tim Robinson Avatar answered Sep 21 '22 13:09

Tim Robinson