设置自定义路径引用的DLL的? [英] Set Custom Path to Referenced DLL's?

查看:626
本文介绍了设置自定义路径引用的DLL的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#项目(称之为 MainProj ),它引用了其他几个DLL项目。通过将这些项目 MainProj 的引用,将建立他们,模仿他们的结果DLL对MainProj的工作目录。

I've got a C# project (call it MainProj) which references several other DLL projects. By adding these projects to MainProj's references, it will build them and copy their resulting DLL's to MainProj's working directory.

我想要做的就是有这些被引用的DLL文件位于 MainProj 的工作目录,即MainProj /斌/ DLL文件的子目录,而不是工作目录本身。

What I'd like to do is have these referenced DLL's be located in a subdirectory of MainProj's working directory, i.e. MainProj/bin/DLLs, rather than the working directory itself.

我不是一个非常有经验的C#程序员,但在C ++的世界即将到来,我假设一种方法是删除项目引用,并明确加载所需的DLL的由路径和文件名(即C ++,调用LoadLibrary )。我想preFER不过的事,如果有一种方法,是设置某种参考二进制文件路径,所以他们就都可以当我建立自动复制到该子目录(然后被引用从那里没有我需要显式地加载每个)。这样的事情可能吗?

I'm not a very experienced C# programmer, but coming from the C++ world, I'm assuming one approach would be to remove the project references and explicitly load the required DLL's by path and filename (i.e. in C++, LoadLibrary). What I'd prefer to do however, if there's a way, would be to set some sort of "reference binary path", so they'd all be auto-copied to this subdir when I build (and then be referenced from there without me needing to explicitly load each). Is such a thing possible?

如果没有,什么是C#中的preferred方法来完成我后(即一些与的Assembly.Load / 大会很.LoadFile / Assembly.LoadFrom ?什么东西在的AppDomain 也许,或统环境?)

If not, what's the preferred method in C# to accomplish what I'm after (i.e. something with Assembly.Load / Assembly.LoadFile / Assembly.LoadFrom? Something in AppDomain perhaps, or System.Environment?)

推荐答案

页面(未经测试由我):

From this page (untested by me):

在某处你的程序的初始化(您访问从引用的程序集的任何类之前)执行此操作:

Somewhere in your program's initialization (before you access any classes from a referenced assembly) do this:

AppDomain.CurrentDomain.AppendPrivatePath(@"bin\DLLs");

编辑: This文章说, AppendPrivatePath被认为是过时的,但也给出了解决方法。

This article says AppendPrivatePath is considered obsolete, but also gives a workaround.

编辑2:的貌似要做到这一点最简单,最洁净的方式是在app.config文件(见的这里):

Edit 2: Looks like the easiest and most kosher way to do this is in the app.config file (see here):

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="bin\DLLs" />
    </assemblyBinding>
  </runtime>
</configuration>

这篇关于设置自定义路径引用的DLL的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆