1 个 DLL 中的私有并行程序集 - 与通常的 DLL 相同吗?

发布于 2024-10-13 21:42:07 字数 432 浏览 7 评论 0原文

我正在研究 Microsoft Windows 中的并行程序集和隔离应用程序解决方案。

文档说:

私有程序集是这样的程序集: 与应用程序一起部署并且是 可供独家使用 该应用程序。

私有程序集必须设计为 与其他版本并行工作 系统上的程序集。

但是,私有程序集的部署过程只是将程序集复制到应用程序的文件夹(或具有程序集名称的子文件夹)中。因此,应用程序不能使用多个版本的私有程序集。因为如果您放置另一个版本的私有程序集 - 它会覆盖旧版本。

有人可以向我解释一下吗?

如果确实如此,那么与具有重定向功能的普通 DLL 相比,此类程序集有何优势?它们对我来说似乎非常相似,并且清单似乎甚至没有在这里使用。

I'm looking at Side-by-Side assemblies and isolated application solution in Microsoft Windows.

Documentation says:

A private assembly is an assembly that
is deployed with an application and is
available for the exclusive use of
that application.

and

Private assemblies must be designed to
work side-by-side with other versions
of the assembly on the system.

However, the deployment process for private assembly is just copying assebly into application's folder (or subfolder with assembly's name). Thus, application can not use more than one version of private assembly. Because if you put another version of private assembly - it'll overwrite old version.

Can someone explain this to me?

If this is indeed so - then what are advantages of such assemblies over usual DLLs with redirection? They seems pretty the same to me and manifest seems not even be used here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-10-20 21:42:08

使用私有 SxS 程序集来部署 dll 实际上只是一种使事情更频繁失败的复杂方法。

不过,也有一些优点:

  • SxS 程序集更安全,因为只会搜索 WinSxS 文件夹和 EXE 文件夹。
  • SxS 程序集对于免注册 COM 是必需的。这意味着您可以部署一个带有捆绑为 SxS 程序集的 COM 对象的应用程序,该应用程序可以通过 XCopy 安装,无需提升。
  • 当您意识到即使作为私有 SxS 程序集安装时,也可以使用该技术加载同一 Dll 的多个不同版本时,SxS 程序集开始变得更加强大。在正常情况下,当 Windows 加载程序加载您的 EXE 文件并处理其清单以创建激活上下文时,它会使用应用程序文件夹作为 SxS 搜索的基本文件夹。

但是,您可以使用


要使用激活上下文 API,您需要:

  • 认识到这不能用于静态绑定资源,因为这些资源始终加载在操作系统加载程序生成的上下文中。

  • 创建一些应用程序清单文件,描述您希望随应用程序一起加载的依赖程序集 - 在外部或嵌入为具有资源 ID 的 RT_MANIFEST 资源 > 16.

  • 填充ACTCTX 包含清单所在位置详细信息的结构,并确保 lpAssemblyDirectory 指向保存特定版本的私有 SxS 程序集的目录。调用 CreateActCtx 创建激活上下文对象。

  • 当需要加载特定版本的 dll 时,使用 ActivateActCtx,然后对 dll 的简单名称调用 LoadLibrary。在调用后停用它,因为加载 dll 后,激活上下文不再需要处于活动状态 - 直到 & 您再次调用需要搜索激活上下文的 API 函数 - 例如,创建 dll 中托管的类的窗口,或创建免注册 com 对象。

加载 dll 时,系统将在提供的 lpAssemblyDirectory 中搜索 dll 及其可能具有的任何依赖程序集。

Using private SxS assemblies to deploy dlls is really just a complicated way of making things fail more often.

There are some advantages however:

  • SxS assemblies are more secure, in that only the WinSxS folder, and the EXE's folder will be searched.
  • SxS assemblies are necessary for registration free COM. Which means you can deploy an app with a COM object bundled as a SxS assembly, that can be installed via XCopy and no elevation.
  • SxS assemblies start to become more powerful when you realize that you CAN use the technology to load multiple different versions of the same Dll even when installed as a private SxS assembly. In the normal course of events, when the Windows Loader loads your EXE file and processes its manifest to create the activation context it uses the application folder as the base folder for SxS searching.

However, you can create your own activation contexts at runtime using the Activation Context API with base folders you specify, that will then be searched for private SxS assemblies. You can use this technique to dynamically load optional assemblies, or different versions of assemblies to implement some kind of plugin api if necessary.


To use the Activation Context API you need to:

  • Realize that this cannot be used for statically bound resources as those are always loaded in a context generated by the OS loader.

  • create some application manifest files describing the dependent assemblies you want to optionally load that you ship with your application - externally, or embedded as RT_MANIFEST resources with resource IDs > 16.

  • Populate an ACTCTX structure with the details of where the manifest is located, and ensure that lpAssemblyDirectory points to a directory holding a specific version of a private SxS assembly. Call CreateActCtx to create an activation context object.

  • When it comes time to load a specific version of the dll, activate the appropriate activation context using ActivateActCtx, then call LoadLibrary on the simple name of the dll. Deactivate it after the call as, with the dll loaded, the activation context is no longer required to be active - until & unless you make another call to an API function that will need to search the activation context - e.g. create a window of a class hosted in the dll, or create a registration free com object.

The system will - while loading the dll - search the provided lpAssemblyDirectory for the dll AND any dependent assemblies it may have.

花辞树 2024-10-20 21:42:08

嗯,每个 EXE 都有自己的私有 DLL。这里没有覆盖,您可以将每个 EXE 放在其自己的安装目录中。他们可以根据设计拥有不同版本的 DLL,DLL Hell 是不存在的。除此之外,这些 DLL 可能会接触文件系统或注册表的其他部分,并互相踩踏。提到“必须设计为并行工作”。这很少是很难实现的。

Well, each EXE will have its own private DLL. No overwriting here, you'd put each EXE in its own install directory. They can have different versions of the DLL by design, DLL Hell is non-existent. Other than that those DLLs might touch other parts of the file system or the registry and step on each other toes doing that. The reference to "must be designed to work side-by-side". This is rarely hard to achieve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文