Thursday, March 27, 2008

Different References between Debug and Release Builds in Visual Studio 2005

What if you want to reference different DLLs in Debug and Release builds of your favorite .NET project? Perhaps you've got some unmanaged DLL spat out by a system that you don't control, but that produces different builds? Or, as in my case, you've got an F# assembly you want to reference from a C# assembly, but F# doesn't yet support "project references", so you have to link directly to the DLL. I'm not convinced what I did will always work, but it seems to right now.

The references in your project (in this case a C# project) are held in a tag called <ItemGroup>. It turns out you can add restrictions to that tag just like you can the other tags in your project, e.g. giving your assembly different names in debug and release modes. So you can end up with something like this.

<ItemGroup> <Reference Include="System" /> <Reference Include="System.configuration" /> </ItemGroup> <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <Reference Include="my favorite debug dll"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\Debug\so-and-so.dll</HintPath> </Reference> </ItemGroup> <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <Reference Include="my favorite debug dll"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\Release\so-and-so.dll</HintPath> </Reference> </ItemGroup>

3 Comments:

At April 22, 2008 2:25 PM, Anonymous Anonymous said...

Good trick indeed. For display purposes however, my version of VS 2005 (8.0.50727) balks. It displays the second (release) reference with a yellow exclamation mark and the properties are missing values. But the debug and release versions are built correctly.

 
At April 22, 2008 2:29 PM, Blogger Sebastian Good said...

Yes, good point. My display also balks, but the build is done correctly. Thanks for mentioning it!

 
At July 10, 2008 1:18 PM, Blogger Ray Henry said...

You can also simply edit the HintPath to say ..\..\$(Configuration)\so-and-so.dll

--Ray
initializecomponent.blogspot.com

 

Post a Comment

Links to this post:

Create a Link

<< Home