7
votes

In the past we have used Advanced Installer to build our .msi installers for a particular project. Our yearly license for Advanced Installer has expired, so to avoid the renewal cost, and because I think the same can be accomplished with Visual Studio, I am attempting to use a Visual Studio 2010 Setup Project to build my .msi.

For the most part, the installer I have built with Visual Studio works fine. However, one thing we need the installer to do is run a couple of .reg files to add a large collection of settings to the registry (It may be worth noting that this is old software that is only being maintained and updated until it is replaced entirely in the near future. It is not practical to change our method of storing settings). With Advanced Installer, we were able to execute a .cmd file as an "Install" Custom Action that would run these .reg files that were also included in the installation. VS Setup Projects have Custom Actions, but it appears that here they are required to be either .dll or .exe files, so I must find an alternative to using a .bat or .cmd file.

First, I tried adding a Command Line project to my solution that consisted only of the following lines in the main() method:

using (Process registryInput = Process.Start("regedit.exe", "/s Settings1.reg"))
{
    registryInput.WaitForExit();
}

using (Process registryInput= Process.Start("regedit.exe", "/s Settings2.reg"))
{
    registryInput.WaitForExit();
} 

I added the Primary Output of this project to the "Install" folder of the "Custom Actions" editor. Tried to run the installer, but the command line process never seemed to run and no registry settings were installed. If I manually ran the command line executable from the application directory where it was installed, it added the registry entries as intended - so the problem is not with the code I'm using to call the .reg files.

I turned to MSDN and changed my solution to be modeled after their Custom Actions Walkthrough. I created a Class Library project (and removed my Command Line project) and added an Installer Class. Instead of starting up a browser using Microsoft's website URL in the Commit() method as shown in their example, I added the code above to the Install() method. Here is what I ended up with:

[RunInstaller(true)]
public partial class Installer1 : System.Configuration.Install.Installer
{
    public Installer1()
    {
        InitializeComponent();
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);

        using (Process registryInput = Process.Start("regedit.exe", "/s Settings1.reg"))
        {
            registryInput.WaitForExit();
        }

        using (Process registryInput = Process.Start("regedit.exe", "/s Settings2.reg"))
        {
            registryInput.WaitForExit();
        } 
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
    }
}

I added the Primary Output of this new Class Library project to the "Install" folder of the "Custom Actions" editor. Still, when I run the installer, the code does not appear to be executed and my registry settings are not added. I have tried this installer both set to "Install for all users" and "This user only".

Any help to either get this Custom Action working or an alternative method to get a .reg file to run on install will be greatly appreciated. Thank you in advance.

4
You can run .cmd or .bat files by using cmd.exe /c <your-script>.cmd.Alexey Ivanov
Try to run your installation with verbose logging: msiexec /i product.msi /l*vx product.log. This log file will have the command lines used to execute your custom actions.Alexey Ivanov
In VS2005 at least, it won't let you enter "cmd.exe /c <your-script>.cmd" as the command to run, you have to choose the file from the folder browser :(gollumullog
further the issue.... xp, the cmd is located in c:\winnt\system32, in windows 7, it is located at c:\windows\system32pithhelmet

4 Answers

5
votes

I just ran across this same issue, re: the custom action not being picked up by the installer. The resolution was to run Visual Studio as an administrator.

Even though I'm a full admin on my machine without any restrictions (AFAIK), the installer would never pick up the custom actions. As soon as I closed down Visual Studio and then restarted as an administrator (right click > run as administrator), the custom actions were immediately picked up by the installer.

1
votes

I banged my head on the keyboard for a bit on this one - and only after putting my custom installation actions in the Constructor of the Installer Class made it run.

I followed the tutorial I found here: http://msdn.microsoft.com/en-us/library/d9k65z2d(v=VS.100).aspx

0
votes

See if this link helps, it helped me:

Visual Studio 2008 Installer, Custom Action. Breakpoint not firing

Basically, code after the

base.Install(stateSaver);

is not getting executed. So put the base.Install(stateSaver); as the last line in the method.

0
votes

This may seem obvious but it caught me out for a while, so might as well post it.

I was just right-clicking on the installer project and then "Install" and "Uninstall". However, you have to rebuild the Installer project after changing the code! (and probably the project with the installer class as well)