Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a reference to be absolute using Visual Studio

Tags:

When adding a reference to a web application project in VS (2008 in this case), the "hintpath" in the csproj file is being created as a relative reference. Is there a way (using the GUI, not manually editing the file) to make this an absolute reference (i.e. C:\Temp\DllName.dll)?

The issue I am running into is when seperate build machines have a different working directories for the project. When the reference is relative, and the referenced dll is not within the project working directory, the relative reference may not point to the same location on both machines.

like image 582
Jeremy Avatar asked May 01 '09 18:05

Jeremy


People also ask

How do you specify an absolute path?

An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory. Relative path is defined as the path related to the present working directly(pwd).

What is absolute path in C#?

An absolute path is the whole path name required to access the location in the file system. For example: C:\Program Files\Internet Explorer\iexplorer.exe.


2 Answers

This is an old question, but it is still relevant. I stumbled upon it while searching for a solution how to reference assemblies from a global repository of third party software.

My approach at the moment is similar to the answer written by thinkOfaNumber. Instead of using a hardcoded absolute path, I prefer embedding an environment variable into the .csproj file. The environment variable then holds the absolute path. Example:

<Reference Include="Foo">
  <HintPath>$(THIRDPARTY_ROOT)\foo\3.1.0\bin\foo.dll</HintPath>
</Reference>

This additional level of indirection gives the flexibility to have different paths on different build machines (e.g. developer system vs. build server).

I still need to manually edit the .csproj file to do this, though.

like image 64
herzbube Avatar answered Nov 04 '22 06:11

herzbube


The only way I have found to do this is by editing the csproj file manually after adding the reference.

<Reference Include="foo, Version=1.2.3.4, Culture=neutral, ...">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>C:\absolute\path\foo.dll</HintPath>
</Reference>

and yes, I hate absolute paths and all the automatic deployment madness it creates, but in this case I have to reference a .NET wrapper that uses a COM dll that has to be "installed" and do things to the registry, etc. so an absolute path is the only way to go.

like image 21
thinkOfaNumber Avatar answered Nov 04 '22 05:11

thinkOfaNumber