Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing C# .dll references from absolute to relative

I have compiled my project and some of my project's added .dlls have absolute references. When I try to run my project on another machine, it looks for the .dlls from the original project path.

How can I make the project look for the .dlls using a relative path?

like image 603
Oded .S Avatar asked Mar 13 '11 16:03

Oded .S


2 Answers

Edit the .csproj file and change the <HintPath> elements from absolute paths to relative paths.

like image 130
SLaks Avatar answered Oct 22 '22 12:10

SLaks


You may also write your handler for resolving assemblies. In the simplest form it may look like this:

AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler;
..
static Assembly AssemblyResolveHandler(object sender, ResolveEventArgs args)
{
  string assemblyPath = "yourpath";
  return Assembly.LoadFrom(assemblyPath + args.Name);
}

Another option is adding entry in App.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="yourpath"/>
     </assemblyBinding>
  </runtime>
like image 34
pkmiec Avatar answered Oct 22 '22 14:10

pkmiec