为免注册 COM 生成清单文件 [英] Generate manifest files for registration-free COM

查看:18
本文介绍了为免注册 COM 生成清单文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些使用清单文件的应用程序(一些本机,一些 .NET),以便它们可以 完全隔离部署,无需任何全局 COM 注册.例如,在与 myapp.exe 位于同一文件夹中的 myapp.exe.manifest 文件中,对 dbgrid32.ocx com 服务器的依赖声明如下:

</dependentAssembly></依赖></组装>

dbgrid32.ocx 与它自己的 dbgrid32.ocx.manifest 文件一起部署到同一文件夹:

<文件名=dbgrid32.ocx"><类型库tlbid="{00028C01-0000-0000-0000-000000000046}"版本=1.0"helpdir=""/><comClass progid="MSDBGrid.DBGrid"clsid="{00028C00-0000-0000-0000-000000000046}"description="DBGrid 控件"/></文件></组装>

这一切正常,但手动维护这些清单文件有点麻烦.有没有办法自动生成这些文件?理想情况下,我只想声明应用程序对 COM 服务器(本机和 .NET)列表的依赖关系,然后让其余部分自动生成.可能吗?

解决方案

看起来完美的解决方案还不存在.总结一些研究:

制作我的清单(link)

此工具扫描 VB6 项目以查找 COM 依赖项,但它还支持手动声明后期绑定的 COM 依赖项(即通过 CreateObject 使用的那些).

有趣的是,该工具将所有有关依赖项的信息放在应用程序清单中.应用程序 exe 及其依赖项被描述为由多个文件组成的单个程序集.我之前没有意识到这是可能的.

看起来是一个非常好的工具,但从 0.6.6 版本开始,它有以下限制:

  • 仅适用于 VB6 应用程序,启动来自 VB6 项目文件.惭愧,因为它所做的很多事情实际上都无关紧要使用 VB6.
  • 向导风格的应用程序,而不是适合集成到构建中过程.这不是一个大问题,如果你依赖项变化不大.
  • 没有来源的免费软件,依赖它有风险,因为它随时可能成为废弃软件.

我没有测试它是否支持 .NET com 库.

regsvr42(codeproject 链接)

此命令行工具为本机 COM 库生成清单文件.它调用 DllRegisterServer,然后在将信息添加到注册表时监视自注册.它还可以为应用程序生成客户端清单.

此实用程序不支持 .NET COM 库,因为它们不公开 DllRegisterServer 例程.

该实用程序是用 C++ 编写的.源代码可用.

mt.exe

windows SDK 的一部分(可以从 MSDN),如果您安装了 Visual Studio,您就已经拥有了.它在此处记录.您可以使用它为本机 COM 库生成清单文件,如下所示:

mt.exe -tlb:mycomlib.ocx -dll:mycomlib.ocx -out:mycomlib.ocx.manifest

您可以像这样为 .NET COM 库生成清单文件:

mt.exe -managedassemblyname:netlib.dll -nodependency -out:netlib.dll.manifest

但是,这个工具存在一些问题:

  • 第一个片段不会生成progid 属性,破坏客户端将 CreateObject 与 progids 一起使用.
  • 第二个片段将生成 元素之前需要剥离的清单确实有效.
  • 生成客户端清单不支持应用程序.

也许未来的 SDK 版本会改进这个工具,我在 Windows SDK 6.0a (vista) 中测试了那个.

I have some applications (some native, some .NET) which use manifest files so that they can be deployed in complete isolation, without requiring any global COM registration. For example, the dependency on the dbgrid32.ocx com server is declared as follows in the myapp.exe.manifest file which sits in the same folder as myapp.exe:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity type="win32" name="myapp.exe" version="1.2.3.4" />
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="dbgrid32.ocx" version="5.1.81.4" />
    </dependentAssembly>
  </dependency>
</assembly>

The dbgrid32.ocx is deployed to the same folder, along with it's own dbgrid32.ocx.manifest file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity type="win32" name="dbgrid32.ocx" version="5.1.81.4" />
  <file name="dbgrid32.ocx">
     <typelib
        tlbid="{00028C01-0000-0000-0000-000000000046}"
        version="1.0"
        helpdir=""/>
    <comClass progid="MSDBGrid.DBGrid"
       clsid="{00028C00-0000-0000-0000-000000000046}"
       description="DBGrid  Control" />
  </file>
</assembly>

This all works fine but maintaining these manifest files manually is a bit of a pain. Is there a way to generate these files automatically? Ideally I would just like to declare the application's dependency on a list of COM servers (both native and .NET) and then let the rest be generated automatically. Is it possible?

解决方案

It looks like the perfect solution does not yet exist. To summarize some research:

Make My Manifest (link)

This tool scans a VB6 project to look for COM dependencies, but it also supports manual declaration of late-bound COM dependencies (i.e. those used via CreateObject).

Interestingly enough, this tool puts all information about the dependencies inside the application manifest. The application exe and its dependencies are described as a single assembly consisting of multiple files. I hadn't realized before that this was possible.

Looks like a very good tool but as of version 0.6.6 it has the following limitations:

  • only for VB6 applications, starts from VB6 project file. Shame, because a lot of what it does really has nothing to do with VB6.
  • wizard style application, not suitable to integrate in a build process. This is not a huge problem if your dependencies don't change a lot.
  • freeware without source, risky to rely on it because it could become abandonware at any moment.

I did not test whether it supports .NET com libraries.

regsvr42 (codeproject link)

This command line tool generates manifest files for native COM libraries. It invokes DllRegisterServer and then spies on the self-registration as it adds information into the registry. It can also generate a client manifest for applications.

This utility does not support .NET COM libraries, since these don't expose a DllRegisterServer routine.

The utility is written in C++. The source code is available.

mt.exe

Part of the windows SDK (can be downloaded from MSDN), which you already have if you have visual studio installed. It is documented here. You can generate manifest files for native COM libraries with it like this:

mt.exe -tlb:mycomlib.ocx -dll:mycomlib.ocx -out:mycomlib.ocx.manifest

You can generate manifest files for .NET COM libraries with it like this:

mt.exe -managedassemblyname:netlib.dll -nodependency -out:netlib.dll.manifest

However, there are some problems with this tool:

  • The first snippet will not generate progid attributes, breaking clients which use CreateObject with progids.
  • The second snippet will generate <runtime> and <mvid> elements which need to be stripped out before the manifests actually work.
  • Generation of client manifests for applications is not supported.

Maybe future SDK releases will improve this tool, I tested the one in the Windows SDK 6.0a (vista).

这篇关于为免注册 COM 生成清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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