ManagedMSIExec - A managed wrapper for MSI'ing
Delay's Blog - “Make things as simple as possible, but not simpler.” [ManagedMsiExec sample app shows how to use the Windows Installer API from managed code]
Windows Installer is the installation and configuration service used by Windows to add and remove applications. (For more information, Wikipedia has a great overview of Windows Installer, covering products, components, setup phases, permissions, etc..) In addition to exposing a rich, native API, Windows Installer comes with
msiexec.exe, a command-line tool that offers fine-grained control over the install/uninstall process.I wanted to familiarize myself with the use of the Windows Installer API from .NET, so I wrote a wrapper class to expose it to managed applications and then a simple program to exercise it. Unlike
msiexec.exewhich can do all kinds of things, myManagedMsiExecsupports only UI-less install and uninstall of a .MSI Windows Installer package (i.e.,/quietmode). By default,ManagedMsiExecprovides simple status reporting on the command line and renders a text-based progress bar that shows how each phase is going. In its "verbose" mode,ManagedMsiExecoutputs the complete set of status/progress/diagnostic messages generated by Windows Installer (i.e.,/l*) so any problems can be investigated.Aside: Although I haven't tested
ManagedMsiExecexhaustively, it's fundamentally just a thin wrapper around Windows Installer, so I'd expect it to work for pretty much any MSI out there.Here's how it looks when run:
...
Of note:
Msi.cs, the class containing a set of .NET platform invoke definitions for interoperating with the nativeMSI.dllthat exposes Windows Installer APIs. The collection of functions and constants in this file is not comprehensive, but it covers enough functionality to get simple scenarios working. Most of the definitions are straightforward, and all of them have XML documentation comments (via MSDN) explaining their purpose. For convenience, many of the relevant Windows error codes fromwinerror.hare exposed by theERRORenumeration.
ManagedMsiExec.cs, the sample application itself which works by calling the relevantMsiAPIs in the right order. Conveniently, a complete install can be done in as few as three calls: MsiOpenPackage, MsiDoAction, and MsiCloseHandle (with MsiSetProperty an optional fourth for uninstall or customization). To provide a better command-line experience, the default UI for status reporting is customized via MsiSetInternalUI, MsiSetExternalUI, and MsiSetExternalUIRecord. Implementing the handler for aMsiSetExternalUIcallback is easy because it is passed pre-formatted strings; parsing record structures in the handler for theMsiSetExternalUIRecordcallback requires a few more API calls (and a closer reading of the documentation!)....
I haven't seen many projects providing a managed wrapper for MSI.DLL
Here's a snap of the Project source;
This looks like a great resource if you need this kind of thing/information...
2 comments:
Ehm, DTF has been out there for quite some time now:
http://robmensching.com/blog/posts/2008/5/16/Deployment-Tools-Foundation-joins-the-WiX-toolset
It is what I believe to be:
1) Complete
2) Documented
3) OpenSource
4) Maintained by people in MS
Nice.. Thanks :)
Post a Comment