简体   繁体   English

更新GAC中的DLL

[英]Updating a DLL in the GAC

I have an API DLL that several third party applications reference. 我有一个API DLL,几个第三方应用程序引用。

Some of these applications want things two ways in terms of updates. 其中一些应用程序在更新方面需要两种方式。 1) I want the latest stuff 2) Don't update my direct binaries that often 1)我想要最新的东西2)不要经常更新我的直接二进制文件

There has been the thought of moving the DLL into the GAC and writing another DLL that is simply the wrapper for the DLL in the GAC (which the 3rd party apps would then reference). 曾经有想过将DLL移动到GAC中并编写另一个DLL,它只是GAC中DLL的包装器(第三方应用程序随后会引用它)。 This allows the business logic (the part that would change frequently) to be updated in the GAC and the wrapper DLL would only need to be updated when new functions were made available. 这允许在GAC中更新业务逻辑(经常更改的部分),并且只有在新功能可用时才需要更新包装DLL。

The GAC is intended to keep versioned DLLs. GAC旨在保留版本化的DLL。 So the wrapper DLL would have a reference to a specific version of the API DLL. 因此,包装器DLL将引用API DLL的特定版本。 How difficult is it to update the GAC DLL so that the references to it don't break but the binary contents differs? 更新GAC DLL以使其对它的引用不会中断但二进制内容不同有多困难?

Is this as simple as not changing GAC DLL versions when updating? 这更简单到更新时不更改GAC DLL版本吗?

Thanks. 谢谢。

How difficult is it to update the GAC DLL so that the references to it don't break but the binary contents differs? 更新GAC DLL以使其对它的引用不会中断但二进制内容不同有多困难?

You can't do it directly. 你不能直接这样做。 You can only put signed DLLs into the GAC. 您只能将已签名的DLL放入GAC。 When you build your app against a signed DLL, the compiler takes a hash of the contents of the DLL and puts it in the app. 当您针对已签名的DLL构建应用程序时,编译器会获取DLL内容的哈希并将其放入应用程序中。 When the .NET runtime loads the app, it checks this hash against the real copy of the DLL. 当.NET运行时加载应用程序时,它会根据DLL的真实副本检查此哈希。 If this DLL doesn't match the one you built with, .NET throws an exception. 如果此DLL与您构建的DLL不匹配,则.NET会引发异常。

The way to work around this is to: 解决这个问题的方法是:

  1. Put in place a version numbering scheme for your GAC DLL. 为您的GAC DLL安装版本编号方案。 This can be as straightforward as always incrementing the version number when you do a build. 这可以像在执行构建时一直增加版本号一样简单。
  2. In your app.config, add a <bindingRedirect> element 在app.config中,添加<bindingRedirect>元素

In effect a binding redirect says, "if you're looking for a DLL with version numbers in the range 1.x to 1.y, look at version 1.z instead". 实际上,绑定重定向表示,“如果您正在寻找版本号在1.x到1.y范围内的DLL,请查看版本1.z”。

Edit: There are ways round the .NET strong name integrity check , but I recommend designing your application around the standard strong name mechanism before trying to circumvent it. 编辑:有很多方法围绕.NET强名称完整性检查 ,但我建议您在尝试绕过它之前围绕标准强名称机制设计应用程序。

You can create an updated assembly, sign it and push it to the GAC so that the applications, which reference this assembly, won't notice the difference. 您可以创建更新的程序集,对其进行签名并将其推送到GAC,以便引用此程序集的应用程序不会注意到差异。 You need to specify all parts of the version number (ie have the version number as 1.2.3.4 and not 1.2.3.* in AasemblyInfo.cs file) and use the same sn key. 您需要指定版本号的所有部分(即版本号为1.2.3.4而不是AasemblyInfo.cs文件中的1.2.3。*)并使用相同的sn键。 Then the version-specific reference won't be broken. 然后,特定于版本的引用将不会被破坏。 And you'll be able to update your DLL as you need. 并且您将能够根据需要更新DLL。

I use Windows Installer to deploy my assemblies to the GAC. 我使用Windows Installer将我的程序集部署到GAC。 From a servicing perspective it's important to understand the difference between: 从服务的角度来看,了解以下两者之间的区别非常重要:

[AssemblyVersion] [的AssemblyVersion]

and

[AssemblyFileVersion] [的AssemblyFileVersion]

The former is considered as part of the strong name contract / binding while the latter is not. 前者被认为是强名称合同/绑定的一部分,而后者则不是。 Additionally the latter is considered by Windows Installer in terms of deciding to overwrite the file or not during an upgrade. 此外,Windows Installer在决定是否在升级期间覆盖文件时考虑后者。

Botton line: If your changes to the assembly doesn't break interfaces or cause any behavior regressions, you can keep the AssemblyVersion the same and increment AssemblyFileVersion and redeploy. Botton line:如果对程序集的更改不会破坏接口或导致任何行为回归,则可以保持AssemblyVersion相同并增加AssemblyFileVersion并重新部署。

This is how .NET Framework Service Packs work as Microsoft has to be able to service the base class libraries without breaking applications that have existing SN references. 这就是.NET Framework Service Pack的工作方式,因为Microsoft必须能够在不破坏具有现有SN引用的应用程序的情况下为基类库提供服务。

References can include version information or reference whatever version is available. 引用可以包括版本信息或引用任何可用的版本。 This is determined by the author of the application that references your DLL. 这由引用您的DLL的应用程序的作者确定。 Of course, you can ship your updated DLL as having the same version as in the GAC, but the whole point of versioning stuff is to let all parties handle updates correctly. 当然,您可以将更新的DLL发布为与GAC中的版本相同,但版本控制的全部内容是让所有各方正确处理更新。 So you might need to refine your task. 所以你可能需要优化你的任务。

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

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