生成免注册COM的清单文件

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

<?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> 

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

 <?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> 

这一切工作正常,但手动维护这些清单文件是有点痛苦。 有没有办法自动生成这些文件? 理想情况下,我只想声明应用程序依赖于COM服务器(本地和.NET)的列表,然后让其余的自动生成。 可能吗?

看起来完美的解决scheme还不存在。 总结一些研究成果:

让我的清单 ( 链接 )

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

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

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

  • 仅适用于VB6应用程序,从VB6项目文件开始。 耻辱,因为它确实与VB6无关。
  • 向导风格的应用程序,不适合在构build过程中集成。 如果你的依赖关系没有改变,这不是一个大问题。
  • 没有源代码的免费软件,依靠它是有风险的,因为它随时都可能成为弃用软件。

我没有testing它是否支持.NET com库。

regsvr42 ( codeproject链接 )

该命令行工具为本地COM库生成清单文件。 它调用DllRegisterServer,然后在registry中添加信息时,探查自我注册。 它也可以为应用程序生成客户端清单。

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

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

mt.exe

部分windows SDK(可以从MSDN下载),如果你已经安装了visual studio,那么你已经拥有了它。 这里logging在案 。 你可以像这样为本地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的客户端。
  • 第二个代码片段将生成<runtime><mvid>元素,这些元素在清单实际工作之前需要被剥离。
  • 不支持为应用程序生成客户端清单。

也许未来的SDK版本会改进这个工具,我在Windows SDK 6.0a(vista)中testing了一个。

使用MSBuild任务GenerateApplicationManifest,我在与Visual Studio生成的清单相同的命令行上生成清单。 我怀疑Visual Studio在构build过程中使用GenerateApplicationManifest 。 下面是我的构build脚本,可以从命令行使用msbuild“msbuild build.xml”

感谢Dave Templin和他的文章,指出了GenerateApplicationManifest任务和MSDN的进一步文档的任务 。

build.xml文件

 <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="Build"> <ItemGroup> <File Include='MyNativeApp.exe'/> <ComComponent Include='Com1.ocx;Com2.ocx'/> </ItemGroup> <GenerateApplicationManifest AssemblyName="MyNativeApp.exe" AssemblyVersion="1.0.0.0" IsolatedComReferences="@(ComComponent)" Platform="x86" ManifestType="Native"> <Output ItemName="ApplicationManifest" TaskParameter="OutputManifest"/> </GenerateApplicationManifest> </Target> </Project> 

让我的清单(MMM)是一个很好的工具。 也可以使用mt.exe编写脚本来处理所有DLL / OCX文件,为每个文件生成一个清单,然后将它们合并在一起。 MMM通常更好/更容易,因为它也处理很多特殊/奇怪的情况。

您可以使用“ 无人值守”使“我的清单”分拆直接在自动构build中生成清单。 它使用脚本文件来添加依赖的COM组件。 这是一个摘录从示例ini与可用的命令:

 # Unattended MMM script # # Command names are case-insensitive. Reference of supported commands: # # Command: Identity # # Appends assemblyIdentity and description tags. # # Parameters <exe_file> [name] [description] # exe_file file name can be quoted if containing spaces. The containing folder # of the executable sets base path for relative file names # name (optional) assembly name. Defaults to MyAssembly # description (optional) description of assembly # # Command: Dependency # # Appends dependency tag for referencing dependent assemblies like Common Controls 6.0, # VC run-time or MFC # # Parameters {<lib_name>|<assembly_file>} [version] [/update] # lib_name one of { comctl, vc90crt, vc90mfc } # assembly_file file name of .NET DLL exporting COM classes # version (optional) required assembly version. Multiple version of vc90crt can # be required by a single manifest # /update (optional) updates assembly_file assembly manifest. Spawns mt.exe # # Command: File # # Appends file tag and collects information about coclasses and interfaces exposed by # the referenced COM component typelib. # # Parameters <file_name> [interfaces] # file_name file containing typelib. Can be relative to base path # interfaces (optional) pipe (|) separated interfaces with or w/o leading # underscore # # Command: Interface # # Appends comInterfaceExternalProxyStub tag for inter-thread marshaling of interfaces # # Parameters <file_name> <interfaces> # file_name file containing typelib. Can be relative to base path # interfaces pipe (|) separated interfaces with or w/o leading underscore # # Command: TrustInfo # # Appends trustInfo tag for UAC user-rights elevation on Vista and above # # Parameters [level] [uiaccess] # level (optional) one of { 1, 2, 3 } corresponding to { asInvoker, # highestAvailable, requireAdministrator }. Default is 1 # uiaccess (optional) true/false or 0/1. Allows application to gain access to # the protected system UI. Default is 0 # # Command: DpiAware # # Appends dpiAware tag for custom DPI aware applications # # Parameters [on_off] # on_off (optional) true/false or 0/1. Default is 0 # # Command: SupportedOS # # Appends supportedOS tag # # Parameters <os_type> # os_type one of { vista, win7 }. Multiple OSes can be supported by a single # manifest #