Generate manifest files for registration-free COM
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).
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
<?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>