How to add a VS assembly reference without hardcoding its path
Note: this entry has moved.
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