共享程序集是否需要只放在GAC中?
我想在两个项目之间共享一个 dll。
dll是否必须只放在GAC中还是可以放在任何文件夹中?
I want to share a dll in between two projects.
Is it necessary to put the dll in GAC only or can I place it in any folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我强烈建议将其保存在每个项目的 Bin 文件夹中。除非确实(确实)有必要,否则不要尝试共享它。
第二个最佳选择是放入共享文件夹(使用相对路径)并在每个项目配置文件中进行配置(
探测路径)。请注意,您始终必须同时更新 2 个项目。如果程序集包含用于在两个项目之间进行通信的类型,那么这是有意义的,但否则这是不必要的复杂化。最后一个选择是将其放入 GAC
I would strongly recommend to keep it in the Bin folder of each Project. Do not attempt to share it unless that is really (really) necessary.
The second best option is to put in a shared folder (using a relative path) and configure that in each Projects config file (
Probing path). Note that you will always have to update the 2 projects simultaneously. If the assembly holds types that are used to communicate between the 2 projects then that makes sense, but otherwise it is a needless complication.The very last option is to put it into the GAC
程序集加载器将在多个位置查找程序集,其中之一是执行目录。
这意味着您可以简单地复制到多个目录。
请参阅
运行时如何定位程序集
在 MSDN 上。The assembly loader will look for the assembly in several places, one of which is the execution directory.
This means that you can simply copy to multiple directories.
See
How the Runtime Locates Assemblies
on MSDN.在您的情况下,我建议您使用源代码控制系统而不是 GAC 来强制执行结构化共享。
Subversion 中的过程:
这为您提供了两全其美的优势:
In your situation I'd recommend using your source control system to enforce structured sharing, not the GAC.
The process in Subversion:
This gives you the best of both worlds: