Daniel Cazzulino's Blog : How to add a VS assembly reference without hardcoding its path

How to add a VS assembly reference without hardcoding its path

Sometimes, you want to add a reference to an assembly provided by VS (that is, something inside the %ProgramFiles%\Microsoft VisualStudio 8.0 folder) that doesn't show up in the Add Reference dialog (there are lots of very interesting stuff you can use that fall under these category, such as Microsoft.Data.ConnectionUI which I used in the GAX TechEd HoL and allows you to create an "Add Data Connection" clone complete with support for .NET providers, connection string builders, test connection, etc.).

The trick is to browse for the reference as usual using the Add Reference dialog, save the project and open it in notepad (or your favorite XML editor). Look for your reference, and replace the hardcoded path to the IDE folder with the $(DevEnvDir) macro variable, like so:

<Reference Include="Microsoft.Data.ConnectionUI, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>$(DevEnvDir)Microsoft.Data.ConnectionUI.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>

The  $(DevEnvDir) variable points to the %ProgramFiles%\Microsoft VisualStudio 8.0\Common7\IDE folder, but you can always use relative path “movements” to go up and around other folders under the root VS install path.

Yes, I know… VS should do that automatically… Go vote the bug so that we have it fixed in Orcas ;-)

Update: I’ve just found that you can also use $(VsInstallDir), which points to  %ProgramFiles%\Microsoft VisualStudio 8.0

posted on Wednesday, March 01, 2006 9:47 PM by kzu

# More on &amp;quot;HOWTO: Using the Choose Data Source dialog of Visual Studio 2005 from your own code&amp;quot; @ Wednesday, January 16, 2008 5:54 AM

Almost one year ago I wrote an article on my web site about how to show the Choose Data Source dialog

Anonymous