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:
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:
You can generate manifest files for .NET COM libraries with it like this:
However, there are some problems with this tool:
<runtime>
and<mvid>
elements which need to be stripped out before the manifests actually work.Maybe future SDK releases will improve this tool, I tested the one in the Windows SDK 6.0a (vista).
With the MSBuild task GenerateApplicationManifest I generated a manifest at the command line identical to the manifest Visual Studio generates. I suspect Visual Studio uses the GenerateApplicationManifest during the build. Below is my build script which can be run from the command line using msbuild "msbuild build.xml"
Thanks to Dave Templin and his post that pointed me the the GenerateApplicationManifest task, and MSDN's further documentation of the task.
build.xml
You can use Unattended Make My Manifest spin off to generate manifests directly in automated builds. It uses a script file to add depended COM components. This is an excerpt from the sample ini with the available commands:
To fill in the ProgIDs that mt.exe doesn't include, you can call
ProgIDFromCLSID
to look them up from the registry. This requires traditional COM registration prior to completing the manifest file, but subsequently, the manifest file will be self-sufficient.This C# code adds the ProgIDs to all COM classes in a manifest:
The code relies on these interop definitions:
Make My Manifest (MMM) is a nice tool for doing this. It's also possible to write a script to process all your DLL/OCX files using mt.exe to generate a manifest for each one and then merge them all together. MMM is usually better/easier, because it also handles lots of special/weird cases.