title: Custom Action not working - Visual Studio Setup Project
body: <p>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 <strong>.msi</strong>.</p>
  
  <p>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 <strong>.reg</strong> 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 <strong>.cmd</strong> file as an "Install" Custom Action that would run these <strong>.reg</strong> 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 <strong>.dll</strong> or <strong>.exe</strong> files, so I must find an alternative to using a <strong>.bat</strong> or <strong>.cmd</strong> file.</p>
  
  <p>First, I tried adding a Command Line project to my solution that consisted only of the following lines in the main() method:</p>
  
  <pre><code>using (Process registryInput = Process.Start("regedit.exe", "/s Settings1.reg"))
  {
      registryInput.WaitForExit();
  }
  
  using (Process registryInput= Process.Start("regedit.exe", "/s Settings2.reg"))
  {
      registryInput.WaitForExit();
  } 
  </code></pre>
  
  <p>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 <strong>.reg</strong> files.</p>
  
  <p>I turned to MSDN and changed my solution to be modeled after their <a href="http://msdn.microsoft.com/en-us/library/d9k65z2d%28v=VS.100%29.aspx" rel="noreferrer">Custom Actions Walkthrough</a>.  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:</p>
  
  <pre><code>[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);
      }
  }
  </code></pre>
  
  <p>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".</p>
  
  <p>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.</p>