如何在不破坏应用程序引用的情况下从部署项目中重新定位程序集?
我最近重构了许多应用程序的现有代码,现在正在考虑整理部署方面的事情。
现有的安装程序应用程序将所有内容安装在应用程序文件夹中(不包括位于子文件夹中的几个配置文件)。但是,我有多个应用程序,它们都使用一些通用程序集,我的目标是将这些特定程序集重新定位到程序文件目录中的“Common Files”文件夹。
注意:我已经阅读了很多有关 GAC,但我没有这方面的经验,也读过一些恐怖故事,所以暂时尝试找到一个简单的解决方案。
我设法将程序集安装到 Common Files 文件夹中,然而,结果(典型的 IT)我破坏了我的应用程序!如果我将程序集复制回应用程序文件夹,它可以正常工作,因此问题显然与我的应用程序引用程序集的方式有关。
为了让安装程序将程序集安装到 Common Files 文件夹中,我刚刚更新了检测到的依赖项
列表中每个程序集的 Folder
属性。我的想法是,当我这样做时,安装程序会以某种方式更新我的应用程序,告诉它在该文件夹中查找它们,但情况似乎并非如此。
我到底做错了什么?
I have recently refactored a lot of my applications existing code and I am now looking at tidying up the deployment side of things.
The existing installer application installs everything in the application folder (with the exclusion of a couple of config files which are located in a sub folder). However, I have multiple applications which all use some common assemblies and my goal is to relocate these particular assemblies to the "Common Files" folder in the program files directory.
NB: I have read a lot about the GAC but I have no experience with it and also read a few horror stories, so trying to get a simple solution for the time being.
I managed to get the assemblies installed into the Common Files folder, however, as a result (typical I.T.) I have broken my app! If I copy the assemblies back into the application folder it works fine so the problem is obviously to do with how my app is referencing the assemblies.
To get the installer to install the assemblies into the Common Files folder I just updated the Folder
property of each assembly in the Detected Dependencies
list. My thoughts were when I did that the installer would somehow update my application to tell it to look in that folder for them but that doens't appear to be the case.
What exactly am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不应该要求程序集位于 GAC 中,除非应用程序/库的开发人员如此设计。您可以选择编写应用程序,以便大多数(如果不是全部)引用的程序集从指定的(公共文件)位置加载。
下面是一个示例架构,它实现了本响应底部引用的 MSDN 文章中描述的技术。
示例:在 SOA 应用程序中,您可能有几个不同的 (Windows) 服务。服务可以在多个服务器之间进行负载平衡。在每个服务器中,服务可以安装在“Services”目录下。位于“Services”目录中的服务可以共享来自(公共文件)“lib”目录的程序集:
每个实际服务都将从使用程序集实用程序的基本服务类派生。您的程序集实用程序可以配置为以系统的方式搜索程序集,从而允许您使用共享/通用程序集。巧妙的是,您的应用程序可以使用本地程序集(在本地开发中)运行,但在部署时使用共享程序集。
在我的现实世界示例中,我有幸拥有自定义构建和部署脚本。想一想您可以部署 N 个服务中的 1 个的不同场景。您是否总是更新(公共文件)“lib”目录?服务可以使用与“lib”程序集不同的本地程序集运行吗?等等
我希望这对您有所帮助。如果您的问题是让第三方安装程序正确部署您的应用程序,请忽略并命名该安装程序。否则,给定的示例/解决方案应该有所帮助:o)
在 MSDN 上阅读该主题:
PS:我在解决 Microsoft Unity 框架的程序集时遇到了挑战。
There should be no requirements for assemblies to be in the GAC, unless the developer of an application/library designed it so. You have the choice to write you application so that most (if not all) referenced assemblies load from a specified (Common Files) location.
Here's an example architecture that implements the technologies described in the MSDN articles referenced at the bottom of this response.
Example: In an SOA application you might have a couple of different (Windows) services. Services could be load balanced across multiple servers. Within each server, services can be installed under a 'Services' directory. Services living in the 'Services' directory could share assemblies from a (Common Files) 'lib' directory:
Every actual service would derive from a Base Service class that would make use of an Assembly Utility. Your Assembly Utility could be configured to search for assemblies in a systematic way, allowing you to use shared/common assemblies. The neat thing is that your application could run with local assemblies (in local development) but use shared assemblies when deployed.
In my real world example, I had the luxury of having custom build and deployment scripts. Think of the different scenarios you can have deploying 1 of N services. Do you always update the (Common Files) 'lib' directory? Can a service run with local assemblies different than the 'lib' assemblies? Etc.
I hope this was helpful. If your issue is getting a third-party installer to deploy your application correctly, then disregard and name the installer. Otherwise, the given example/solution should help :o)
Read on the subject at MSDN:
PS: I've had challenges resolving assemblies for Microsoft's Unity framework.
如果您希望从公共文件夹“引用”某些程序集,则可以在开发时进行。然而,在部署每个应用程序时,都必须安装这些单独的程序集。
如果在运行时,多个应用程序共享某些程序集,那么“该公共文件夹”就是 GAC。
If you wish to "reference" some assemblies from common folder, it is possible at development time. However when deploying every application has to have those individual assemblies installed with them.
If at run time, more than one of your applications are sharing some assemblies then "that common folder" is GAC.