如何构建/部署项目,需要多个版本的同一程序集的? [英] How to build/deploy project that requires multiple versions of the same assembly?

查看:230
本文介绍了如何构建/部署项目,需要多个版本的同一程序集的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用conflict.dll 6.2版的一个项目,但该项目还采用了使用conflict.dll 5.8版helper.dll。

I am working on a project that uses conflict.dll version 6.2, but the project also uses helper.dll that uses conflict.dll version 5.8.

我可以安装6.2和5.8到GAC,但I'ld喜欢这个项目XCOPY部署。我相信.NET将搜索像这样的应用程序bin目录中的组件: \ BIN \ conflict.dll(6.2) \ BIN \ 5.8 \ conflict.dll(5.8)

I could install 6.2 and 5.8 into the GAC, but I'ld like to have this project xcopy deployable. I believe .net will search for the assemblies in the application bin directory like so: \bin\conflict.dll (6.2) \bin\5.8\conflict.dll (5.8)

不过,在这一点上,我怎么添加项目引用conflict.dll的两个版本,然后我如何确保老conflict.dll部署到\ BIN \ 5.8?难道我创建了一个生成操作或有另一种方式?

But at this point, how do I add a reference to both versions of conflict.dll in the project, and then how do I make sure the old conflict.dll deploys to \bin\5.8? Do I create a build action or is there another way?

感谢

推荐答案

在支持达林的回答,当然你需要消除这种多版本问题。他使​​用绑定重定向的解决方案是一个很好的 - +1那里。我可以提供一个解决方案,将允许在绝对必要时双方你保持,但你必须写一点code。

In support of Darin's answer of course you need to be eliminating such multi-version problems. His solution of using a binding redirect is a good one - +1 there. I can offer a solution that'll allow you to keep both if absolutely necessary, but you'll have to write a bit of code.

唯一真正的问题,你在这里是两个部署的文件名必须是相同的,以被拾起违约装载机。你可以欺骗真的很可怕,简单地部署5.8 DLL作为 Conflict.exe ,以便它可以并排坐 Conflict.dll (及更新版本),你会发现,它的作品。

The only real problem you have here is that the two deployed filenames would have to be the same in order to be picked up by default by the loader. You could cheat really horribly and simply deploy the 5.8 dll as Conflict.exe so it could sit side by side Conflict.dll (and newer) and you'd find that it works.

另外,从达林的回答下面通过链接你来这个话题MSDN主题在探测。基于这个内容,你可以简单地部署5.8 DLL到BIN \内容\ Content.dll,当它运行时的搜索,它会自动查找该子文件夹。

Also, following the links through from Darin's answer you come to this topic MSDN topic on probing. Based on the content of this, you could simply deploy the 5.8 dll into bin\Content\Content.dll and when the runtime searches for it, it will look in this subfolder automatically.

但是 - 这不是一个很好的解决方案:)

However - that isn't a good solution :)

编辑 - 新的解决方案

如果Conflict.dll的两个版本都已经签约,你确实尝试部署版本之一略有不同的名字?我刚刚建立了一个WinForms应用程序有两个组件引用不同版本的同一(签字)组装。这会导致一些问题与构建,因为最后引用的版本将被部署到bin文件夹,而其他人会不会(所以你必须在这两个手动复制,重命名其中一个相应的)。然后,我尝试运行应用程序,这将显示包含两个常量字符串的消息框;从每个版本的程序集。它的工作原理精绝。

If both versions of Conflict.dll are already signed, have you actually tried deploying one of the versions with a slightly different name? I've just set up a winforms app with two assembly references to different versions of the same (signed) assembly. This causes a couple of problems with the build, because the last-referenced version will be deployed to the bin folder, and the other one will not (so you have to manually copy in both; renaming one of them accordingly). Then I try running the app, which displays a message box containing two constant strings; one from each version of the assembly. It works absolutely fine.

<一个href="https://docs.google.com/leaf?id=0Bw_NnV9fhgmgZjY1ZDllZDAtMTk0ZC00YTI3LTljYmItY2YwNGUwMzg2NzYw&sort=name&layout=list&num=50"相对=nofollow>这里下载这个演示 - 不要构建它(否则你必须做的文件重命名);只需打开窗体应用程序的bin \ debug文件夹,然后运行exe文件。

Download a demo of this here - don't build it (otherwise you have to do the file renaming); just open the forms app's bin\debug folder and run the exe.

ClassLibrary1.dll和ClassLibary1vanything.dll是V1.0.0.0和装配的V2.0.0.0与否则相同的名称和公开密钥。尽管classlibrary1vanything.dll有错误的文件名,它仍然有效(可能是因为它的签署)。事实上

ClassLibrary1.dll and ClassLibary1vanything.dll are v1.0.0.0 and v2.0.0.0 of an assembly with otherwise the same name and public key. Despite the fact that classlibrary1vanything.dll has the wrong filename, it still works (probably because it is signed).

在我的app.config并投入了codeBase的提示,并认为这就是为什么它的工作(我原本部署它作为一个不同的文件名),但后来我评论它,它仍然工作。在codeBase的可能是最有用的,而不是在联合国大会被部署到一个子文件夹或完全不同的位置。

In the app.config I did put in a codebase hint, and thought that was why it worked (originally I deployed it as a different filename), but then I commented it out and it still worked. The codebase is probably most useful instead when the assembly has to be deployed to a sub folder or completely different location.

原文

我试图让从MS 此支持文章中提到的第二个选项工作,但它似乎并不想。

I've tried to get the second of the options mentioned in this support article from MS to work, but it doesn't seem to want to.

毫无疑问,一些聪明的方式做到这一点开箱即用,但因为我不是足够聪明地发现它(还),我反而美化,并使用在上述支撑显示的选项第三主题,钩到应用程序域的 AssemblyResolve 事件。

There is no doubt some clever way to do it out of the box, but since I'm not clever enough to have found it (yet), I would instead embellish and use the third of the options displayed in the aforementioned support topic and hook into the AssemblyResolve event of the app domain.

如果你的程序集的全名添加自己的配置(可能只是在的appSettings真的)绑定到不同的文件名,然后在您的AssemblyResolve事件处理程序,你可以参考的是要加载的程序集的名称看它是否在您的配置。如果是,位置和使用Assembly.LoadFrom抢抱到加载它。

If you add your own configuration (probably just in appSettings really) for the full name of the assembly to be bound to a different filename, then in your AssemblyResolve event handler you can consult the name of the assembly that is to be loaded to see if it's in your configuration. If it is, grab hold of the location and use Assembly.LoadFrom to load it.

因此​​,一旦你有这样的事情在发生,你只要在那里与该应用程序应该使用的文件名添加的冲突V5.8组件名的条目。

Thus, once you have something like this in place, you simply add an entry for the Conflict v5.8 assembly name in there along with the filename that the app should use.

我不知道它是什么类型的应用程序,你部署但在胜利的形式,控制台应用程序和服务 AppDomain.CurrentDomain.BaseDirectory 将等于bin文件夹,你可以加入你要​​加载的文件名。网站是有点棘手。

I don't know what type of app it is that you're deploying but in win forms, console apps and services AppDomain.CurrentDomain.BaseDirectory will be equal to the bin folder and you can join that with the filename you want to load. Websites are a little trickier.

应工作一种享受。

这篇关于如何构建/部署项目,需要多个版本的同一程序集的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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