简体   繁体   English

.Net在两个Web服务之间共享dll

[英].Net share dll's between two Web Services

I have two web services that are both contained underneath a common subdirectory 我有两个Web服务都包含在一个公共子目录下

CompanyName\Service1
CompanyName\Service2

Each directory has a bin folder that contains its dlls. 每个目录都有一个包含其dll的bin文件夹。 I've now come to a point where some of this code has been restructured and has quite a few common components and i'd like to be able to 'share' them. 现在,我要说的是,其中一些代码已进行了重组,并具有许多通用组件,我希望能够“共享”它们。 What would be the best way to go about this? 最好的方法是什么? Below is a list of solutions I have found (along with the negatives). 以下是我找到的解决方案列表(以及底片)。

  • AssemblyResolving - Security issues. AssemblyResolving-安全问题。
  • codeBase element inside of web.config - Hardcoded paths to component locations. web.config内部的codeBase元素-组件位置的硬编码路径。
  • GAC - Currently non of our products use the GAC and I personally have very limited knowledge on using it. GAC-目前,我们的产品均未使用GAC,而我个人对使用GAC的知识非常有限。 This one may just be a fear of the unknown. 这可能只是对未知的恐惧。
  • Place assemblies in both locations - Harder to update in place patches. 将装配件放置在两个位置-难以更新到位补丁。 Need to ensure files get replaced in all locations. 需要确保文件在所有位置都被替换。

Am I missing anything else that could be helpful to me? 我是否还有其他可能对我有帮助的东西? Would anyone recommend using any of the options listed above? 有人会建议使用上面列出的任何选项吗?

Additionally, I cannot combine the two services into as they are currently used by third parties (they were build separately). 此外,我无法将这两项服务合并为第三方当前使用的服务(它们是分别构建的)。

i would go for the GAC, since is solves all your other problems that you listed, plus it looks natural that a shared library will be in one location. 我会去GAC,因为它可以解决您列出的所有其他问题,而且共享库位于一个位置看起来很自然。

to use the GAC, all you need it to strong name the dll, and drop it in the GAC in install time it also gives you good side by side versioning options (one WS using version 1.0.0.0 , another can use 1.0.0.1) 要使用GAC,只需要将其强名命名为dll,然后在安装时将其放到GAC中,它还会为您提供良好的并排版本控制选项(一个WS使用1.0.0.0版,另一个WS使用1.0.0.1版)

You best best is almost assuredly updating both services at once. 您最好的是几乎可以肯定地同时更新这两种服务。 Take a look at your deployment process if this is something that worries you. 如果这让您感到担心,请查看您的部署过程。

The other real option is using the GAC. 另一个实际选择是使用GAC。 The GAC comes with it's own problems such as having to strong name/sign your assemblies and more deployment issues. GAC自身存在一些问题,例如必须使用强名称/对程序集签名/签名以及更多部署问题。

In relation to the build system, if you always build and deploy both web services at the same time then you won't have to worry about mix-matches since you indicated the assemblies need to stay the same between services. 关于构建系统,如果您始终同时构建和部署两个Web服务,则不必担心混合匹配,因为您指出组件需要在服务之间保持不变。 If you aren't using a CI system, I would suggest you start one, TeamCity is a great one to start with and it's free (well, for a limited number of users/projects - enough to get you started). 如果您不使用CI系统,建议您从一个CI系统开始。TeamCity是一个很好的起点,它是免费的(嗯,对于有限数量的用户/项目-足以让您入门)。 Then just deploy from CI, either directly or from packages generated from there. 然后,可以直接从CI部署,也可以直接从CI部署生成。 I'll admit CI is a bit to tackle for solving one problem but it can help make your life easier if you embrace it in the long run. 我承认CI对于解决一个问题有点困难,但是如果您长期接受,它可以使您的生活更轻松。

Both locations. 两个位置。 That way you can publish a change to the common code in one version (interface change / breaking change), by replacing the files in that bin folder, without endangering/breaking the other web service. 这样,您可以通过替换该bin文件夹中的文件,在一个版本中发布对通用代码的更改(界面更改/中断更改),而不会危及/中断另一个Web服务。

Update: this has the same "side-by-side versioning" advantages as using the GAC, without any of the coordinated publishing complexity, strong naming requirements, etc. 更新:与使用GAC具有相同的“并排版本控制”优势,而没有任何协调的发布复杂性,强大的命名要求等。

Another option is to put the files in a single location and link to them using a symbolic link. 另一种选择是将文件放在单个位置,然后使用符号链接链接到它们。 This thread explains the command. 线程解释了该命令。

I have no experience of trying this so would not recommend it. 我没有尝试过的经验,因此不推荐使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM