Nerdy tidbits from my life as a software engineer

Thursday, April 9, 2009

There Has To Be a Better Way

Is there anything more aggravating than writing MSI’s?  There’s simply no easy way to run and test them, and the documentation on MSDN is beyond poor.  For instance, say you want to write a custom action that does something based on the location where your product was installed.  How do you get the installation directory in your installer?  If you check the documentation on MSDN, you’ll spin your wheels for hours and come up empty handed.  And since you can’t debug MSI’s, you’re left to doing horrible things like this to find out which string you need to hard code into your installer in order to find the right property in the Context.Parameters dictionary:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Configuration;
using System.Configuration.Install;

namespace MyInstallers
{
    [RunInstaller(true)]
    public class SetupCustomAction : Installer
    {
        public SetupCustomAction()
        {
        }

        protected override void OnAfterInstall(IDictionary savedState)
        {
            foreach (DictionaryEntry entry in this.Context.Parameters)
            {
                // Can you believe this nonsense?!
                System.Windows.Forms.MessageBox.Show(entry.Key + "=" + entry.Value);
            }

            base.OnAfterInstall(savedState);
        }

    }
}

My Lord is this terrible.  Can you believe this is what I had to find the answer to my simple question?  How else are you supposed to figure out that this.Context.Parameters[“assemblypath”] is what you’re looking for?  If anybody has a better way, please let me know.

0 comments: