views:

2038

answers:

4

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?

+3  A: 

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.

Freddy
You don't need to add the dll to the project itself, just add reference to it. The best thing to do is to add the whole 'lib' directory to your source control. See http://code.google.com/p/projectpilot/source/browse/#svn/trunk as an example
Igor Brejc
You are right. I checked an old project and neither the directory or the dlls were added to the project itself, just to the repository. And the reference is then relative to the project. Sorry about that.
Freddy
A: 

When you go to your project, right click on References and click Add Reference, go to the Browse tab and you can add a dll from anywhere within your solution (i.e. in a Library folder in the root directory of your solution).

cbp
A: 

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.

Uwe Honekamp
I think it is not necessary to modify the project file manually. In my experience Visual Studio always uses relative pathes. The only time I had to modify the project file by hand was when I wanted to share a key file (.snk). Visual Studio always just copies the key file into the project directory which results in several copies of the key file.
Stefan Egli
+2  A: 

I agree with Pavel Minaev's original comment on jimioh's post above ( I cannot comment on it directly because I don't have enough points)

To expand on this - 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-click 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. (Also remove the spaces between angle brackets and HintPath)

Hope this helps.

CrimsonX