Saturday, February 19, 2011

Quick tip: Linking against appropriate assembly depending on your configuration in VS.NET

Occasionally, while developing a .NET app, I've needed to reference an assembly from another solution from within my current one. Most often I see projects referencing either the debug or release versions directly, but what happens if you want to reference an assembly for the same configuration that your current solution is in? (i.e. referencing an external debug mode assembly while you're in debug mode and a release mode assembly in release mode)

The answer is an easy one, but can't be done directly by the IDE.

Reference the debug version of the  assembly you want to as per normal.

Next right click the project, which you just added the assembly to, and select edit project file. This will bring up the project's msbuild file.

Find the reference to the assembly you just added and replace the text Debug in the HintPath with $(Configuration)

Save and close the project file then reload the project. That's it! Now when you compile in debug or release mode the correct version of the referenced assembly will be compiled too.

NB: this assumes the dependant assemblies are located in Debug and Release folders off of the same parent folder.

No comments:

Post a Comment