views:

36

answers:

2

Hello:

I am working on VS2010 C# and I want to add a .dll reference compiled under VS2008; this .dll exists in 2 versions: Debug and Release.

The .dll is not under .NET, COM or projects tabs, so I only have the "browser" tab to add the .dll to the reference.

My question is: How can I indicate to VS to take the release .dll version when I compile in the release mode and to take the debug .dll version when I compile in the debug mode?

Thanks.

+1  A: 

You'll probably need to manually edit the underlying .csproj file. Approximately thusly

<Reference Condition=" '$Configuration'=='Debug' " 
           Include="path\to\Debug\Foo.dll" />
<Reference Condition=" '$Configuration'=='Release' " 
           Include="path\to\Release\Foo.dll" />

(May be easy to add a reference to debug version via browse, then right click project in solution explorer, click 'Unload project', then right click again, 'Edit your.csproj', make the edit suggested above to the Foo.dll that you just added, then right click, 'Reload project'.)

EDIT

To prevent seeing two copies inside VS, maybe something like

<Reference debugstuff as before>
    <Visible Condition=debugcond>true</Visible>
    <Visible Condition=releasecond>false</Visible>
</Reference>
and same for release

That is, conditionally set Visible metadata under the reference node to true/false based on the condition. I haven't tried to to know if it works.

Brian
Thanks Brian, it is working now. Please, let me ask a one more question related to your answer. When I see the reference option, two lines referred to both the path\to\Debug\Foo.dll and the path\to\Release\Foo.dll are displayed; how can I avoid this behavior? I mean, if I am in Debug mode only the line related to path\to\Debug\Foo.dll should be displayed and so on. Thanks!!
I added to my answer something to try.
Brian
Brian, seems it doesn't work, the "Visible Condition" is not been recognized by VS. Anyway, your first solution works for me. My best regards.
+1  A: 

The standard approach is to add the project to the solution. It is then entirely automatic.

Hans Passant
Thanks Hans, my problem here is that the .dll components I want to add in the reference were compiled in VS2008. When I try to add the project into the VS2010 solution, it forces me to upgrade the project. I would not like to have duplicated projects (one in 2008 and another in 2010).
You've already got some projects that only load in 2008, some in 2010. I recommend you don't let that linger on for too long. SCCSs are built to make that *not* a problem.
Hans Passant
Hello Hans, I appreciate your recommendation very much. In this moment I am using a trial version of VS2010 and I am not sure if my company is going to pay for it so, I do not want to touch the VS2008 components. Thanks!!