Visual Studio: Relative Assembly References Paths

Visual Studio-2008ReferenceRelative Path

Visual Studio-2008 Problem Overview


When adding a reference to an assembly located within the solution directory, is there any way to add it relatively, so that when checked in and out of a repository it is referenced in projects correctly?

Visual Studio-2008 Solutions


Solution 1 - Visual Studio-2008

To expand upon Pavel Minaev's original comment - The GUI for Visual Studio supports relative references with the assumption that your .sln is the root of the relative reference. So if you have a solution C:\myProj\myProj.sln, any references you add in subfolders of C:\myProj\ are automatically added as relative references.

To add a relative reference in a separate directory, such as C:/myReferences/myDLL.dll, do the following:

  1. Add the reference in Visual Studio GUI by right-clicking the project in Solution Explorer and selecting Add Reference...

  2. Find the *.csproj where this reference exist and open it in a text editor

  3. Edit the < HintPath > to be equal to

    <HintPath>..\..\myReferences\myDLL.dll</HintPath>

This now references C:\myReferences\myDLL.dll.

Hope this helps.

Solution 2 - Visual Studio-2008

Yes, just create a directory in your solution like lib/, and then add your dll to that directory in the filesystem and add it in the project (Add->Existing Item->etc). Then add the reference based on your project.

I have done this several times under svn and under cvs.

Solution 3 - Visual Studio-2008

In VS 2017 it is automatic. So just Add Reference as usually.

Note that in Reference Properties absolute path is shown, but in .vbproj/.csproj relative is used.

<Reference Include="NETnetworkmanager">
      <HintPath>..\..\libs\NETnetworkmanager.dll</HintPath>
      <EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>

Solution 4 - Visual Studio-2008

Probably, the easiest way to achieve this is to simply add the reference to the assembly and then (manually) patch the textual representation of the reference in the corresponding Visual Studio project file (extension .csproj) such that it becomes relative.

I've done this plenty of times in VS 2005 without any problems.

Solution 5 - Visual Studio-2008

I might be off here, but it seems that the answer is quite obvious: Look at reference paths in the project properties. In our setup I added our common repository folder, to the ref path GUI window, like so

Reference Paths in VS20xx

That way I can copy my dlls (ready for publish) to this folder and every developer now gets the updated DLL every time it builds from this folder.

If the dll is found in the Solution, the builder should prioritize the local version over the published team version.

Solution 6 - Visual Studio-2008

As mentioned before, you can manually edit your project's .csproj file in order to apply it manually.

I also noticed that Visual Studio 2013 attempts to apply a relative path to the reference hintpath, probably because of an attempt to make the project file more portable.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontheringostarrsView Question on Stackoverflow
Solution 1 - Visual Studio-2008CrimsonXView Answer on Stackoverflow
Solution 2 - Visual Studio-2008FreddyView Answer on Stackoverflow
Solution 3 - Visual Studio-2008Iurii VasylenkoView Answer on Stackoverflow
Solution 4 - Visual Studio-2008Uwe HonekampView Answer on Stackoverflow
Solution 5 - Visual Studio-2008ChristianView Answer on Stackoverflow
Solution 6 - Visual Studio-2008Nick LouloudakisView Answer on Stackoverflow