Changing C# .dll references from absolute to relative

后端 未结 2 1169
眼角桃花
眼角桃花 2021-02-13 06:35

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 orig

相关标签:
2条回答
  • 2021-02-13 07:01

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

    0 讨论(0)
  • 2021-02-13 07:19

    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>
    
    0 讨论(0)
提交回复
热议问题