程序集的版本控制问题
假设我有两个程序集:
MyExecutable.dll version 1.0.0
MyClassLibrary.dll version 1.0.0
现在,MyExecutable.dll
当前使用 MyClassLibrary.dll
的类和方法(其中包括一些算法)。大多数这些算法都是在运行时制定的,以后如果需要的话我会想改进它们。这意味着,我不会更改这些类的接口,但代码本身会发生一些变化。
目前的问题是,MyExecutable.dll
将期待 MyClassLibrary.dll 1.0.0
并且我希望它使用版本 1.0.1(或类似的版本) 。我不想重新编译 MyExecutable.dll
(因为实际上可能不止一个可执行文件使用 MyClassLibrary.dll
)。这个问题有解决办法吗?我听说过 GAC
,但如果可能的话,我想远离它。
谢谢
Let's assume I have two assemblies:
MyExecutable.dll version 1.0.0
MyClassLibrary.dll version 1.0.0
Now, MyExecutable.dll
currently uses MyClassLibrary.dll
's classes and methods (which include some algorithms). Most of those algorithms were made on the run, being that later I'll want to refine them if needed. This means, I won't change the interface
of those classes but the code itself will see some changes.
The question at hand is, MyExecutable.dll
will be expecting MyClassLibrary.dll 1.0.0
and I'll want it to use version 1.0.1 (or something like that). I don't want to have to recompile MyExecutable.dll
(because actually there might be more than just one executable using MyClassLibrary.dll
). Is there a solution for this problem? I've heard about the GAC
, but if possible I'd like to stay away from it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找
程序集绑定重定向
- 这是一种可配置的方式来告诉 .NET 使用哪个版本的程序集。You are looking for
Assembly Binding Redirection
- this is a configurable way to tell .NET what version assemblies to use.第一个解决方案是程序集绑定重定向,Oded 已推荐。
如果您有一个较小的 .dll 并且想让某些东西与其较新的版本一起工作,那么这是有利的。
第二个选项是为接口创建一个单独的程序集,并仅引用可执行文件中的程序集。
这样,您可以允许第三方针对您的库构建内容,而无需向他们提供确切的库程序集。 (例如,他们无法使用 Reflector 对其进行反编译,因此这种方式更安全。)
只要界面组件不改变,您就可以根据需要更改库中的其他内容。
The first solution is Assembly Binding redirection, already recommended by Oded.
It is advantageous if you have a smaller .dll and want to make something work with its newer versions.
The second option is creating a separate assembly for the interfaces, and referencing only that from the executable.
This way, you can allow third parties to build stuff against your library without giving them the exact library's assembly. (Eg. they can't decompile it with Reflector, so it is more secure this way.)
As long as the interface assembly doesn't change, you can change other stuff in the library pretty much as you want.