Custom Action not working - Visual Studio Setup Project

12,384

Solution 1

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.

Solution 2

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

Share:
12,384
Tim Coolman
Author by

Tim Coolman

Updated on June 24, 2022

Comments

  • Tim Coolman
    Tim Coolman almost 2 years

    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.

    • Alexey Ivanov
      Alexey Ivanov almost 13 years
      You can run .cmd or .bat files by using cmd.exe /c <your-script>.cmd.
    • Alexey Ivanov
      Alexey Ivanov almost 13 years
      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.
    • gollumullog
      gollumullog almost 13 years
      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 :(
    • pithhelmet
      pithhelmet about 11 years
      further the issue.... xp, the cmd is located in c:\winnt\system32, in windows 7, it is located at c:\windows\system32
  • E.Z. Hart
    E.Z. Hart almost 13 years
    Thank you. You just saved me the cost of a new monitor. I was about two seconds away from punching it.