C#将所需的DLL放在输出根目录以外的地方 [英] C# Putting the required DLLs somewhere other than the root of the output

查看:1250
本文介绍了C#将所需的DLL放在输出根目录以外的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EmguCV作为一个项目,当我们的程序运行它需要一些像cxcore.dll等dll(或它抛出运行时异常)。目前,我将文件放在输出文件夹的根目录(选择永远复制在Visual Studio的文件属性中)。



但是它看起来有点凌乱,在那里有大约10个不同的dll。有没有可以将它移动到输出文件夹中的子文件夹,它仍然会找到它。

解决方案

令人惊讶的答案至今。没有正确的;)嗯,



是的,你可以将程序集放在不同的位置。



应用程序配置( app.config 将其复制到 your.exe.config )add:

 < runtime> 
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< probing privatePath =lib/>
< / assemblyBinding>
< / runtime>

根据:



http://msdn.microsoft.com/en-us/library/823z9h8w.aspx



这将使程序查看程序集中的专用路径(它自己的文件夹下的文件夹) - 就像Web应用程序查找/ bin一样。



你也可以把它们放在GAC中,但是除非有其他的原因,否则应该避免。



说,你真的不需要。如果您在开始菜单中正确安装应用程序,用户不会感到困惑;)我从来没有遇到过这个问题,包括具有50多个程序集的项目。用户simlpy从来没有看到他们。


I am using EmguCV for a project and when our program runs it needs some dlls like "cxcore.dll" etc. (or it throws runtime exceptions). At the moment, I put the files in the root of the output folder (selected "Copy Always" in the file's properties in Visual Studio).

However it looks a bit messy, to have about 10 different dlls just there. Is there someway where I can move it to a subfolder in the output folder and it'll still find it.

解决方案

Amazing answers so far. None right ;) Well,

yes, you can put the assemblies in separate locations.

In the corresponding application config (app.config which gets copied to your.exe.config) add:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>

According to:

http://msdn.microsoft.com/en-us/library/823z9h8w.aspx

This will make the program look into the private path (folders under it's own folder) for assemblies - much like a web application looks for /bin.

You can also put them into the GAC, but that should be avoided unless there are other reasons for this.

That being said, you really dont need to. Users wont get confused if you install the application properly in the start menu ;) I never had that problem, including projects with 50+ assemblies. Users simlpy never see them.

这篇关于C#将所需的DLL放在输出根目录以外的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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