36

I have tried to create a custom action for a Visual Studio Installer project to modify the permissions for a config file.

The Installer.cs is as follows:

public override void Commit(IDictionary savedState)
{
    base.Commit(savedState);

    // Get path of our installation (e.g. TARGETDIR)
    //string configPath = System.IO.Path.GetDirectoryName(Context.Parameters["AssemblyPath"]) + @"\config.xml";
    string configPath = @"C:\Program Files\Blueberry\Serial Number Reservation\config.xml";

    // Get a FileSecurity object that represents the current security settings.
    FileSecurity fSecurity = File.GetAccessControl(configPath);

    //Get SID for 'Everyone' - WellKnownSidType works in non-english systems
    SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

    // Add the FileSystemAccessRule to the security settings.
    fSecurity.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));

    // Set the new access settings.
    File.SetAccessControl(configPath, fSecurity);

}

public override void Install(IDictionary stateSaver)
{
    base.Install(stateSaver);
}

public override void Rollback(IDictionary savedState)
{
    base.Rollback(savedState);
}

public override void Uninstall(IDictionary savedState)
{
    base.Uninstall(savedState);
}

Then I add the Primary Output (Installer class = true) into the Commit section of the setup project's Custom Actions.

When I run the installer, I get the following error:

Error 1001: Could not find file 'c:\mypath\myapp.InstallState'

Scouring the web I've found a few examples of similar experiences, but none of the solutions offered have worked for me.

Any ideas?

12 Answers 12

55

You can find a solution here

To quote:

The problem is that the MSI infrastructure is looking for the installation state file which is usually created during the Install phase. If the custom action does not participate in the Install phase, no file is created.

The solution is to add the custom action to both the Install and the Commit phases, although it does nothing during the install phase.

2
  • This isn't accurate. You don't have to add anything to both phases. I added an update at that link. I used just the Install override in the Installer class after adding the "Primary output" to each section in the Custom Actions. I set my CustomActionData value on the Install phase Primary output properties. I ignored the other phases altogether in my Installer class - they don't need to be overridden and will just do what they always did. I got the same error as the OP until I added a closing quote around one of my textbox names that was in my CustomActionData string that was missing.
    – vapcguy
    Commented Dec 1, 2016 at 21:04
  • Thank you so much! I've been searching for hours.
    – Fredy
    Commented Jul 11 at 12:46
19

I had this problem when I didn't specify a custom action in my installer project for all four overrides (Install, Uninstall, Commit, and Rollback). As soon as I specified my project output as the custom action for all four, the issue went away.

The only overrides in my installer class that did anything were Commit and Uninstall; I think that Install was in charge of creating the InstallState file in the first place, and since it was never called the InstallState file was never created.

2
  • I did actually try this when I received your post, but IIRC it didn't work. I had all 4 overrides covered (albeit a couple did very little) but the problem remained. Unfortunately, I abandoned this project (long story) about a week after posting, so it's unlikely I'll ever go back and report a solution.
    – CJM
    Commented Feb 4, 2012 at 22:07
  • 2
    Worked for me just adding the project output to the Install custom action (not unintall or rollback). I was getting the error 1001 when it was only added to Commit custom action.
    – JimSTAT
    Commented Jul 9, 2012 at 17:24
3

Sometimes this happens when the installer class is not created correctly. Here is a tutorial which may help you: http://devcity.net/Articles/339/1/article.aspx

Make sure that your custom action follows the tutorial recommendations.

2
  • 2
    This was the case for me, in Custom Action Properties, the property named InstallerClass was set to True, when I needed it to execute - so changing it to False did the trick for me.
    – JasonH
    Commented Mar 23, 2016 at 17:33
  • Had the error the OP had and changing the InstallerClass property had no effect, for me - either before or after I fixed my real issue-which was fixing a missing quote in my CustomActionData value.
    – vapcguy
    Commented Dec 1, 2016 at 21:16
3

Sometimes, "Debugger.Launch();" is put at those overwritten functions for debugging. If you build the installer with the statement there, and during your installation, a dialog will popup to ask you whether debug is needed, if you press 'cancel debugging', you'll get this error dialog. Because you added the 'Debugger.Launch()' at your function, then that function will be considered as 'missed' by installer. So, don't forget to remove it.

2
  • The debugger statement in the code I shamelessly copied wasn't even causing a popup, just a miserable failure leading to "InstallState not found" for no apparent reason wasting a couple of hours of my life.
    – Andre Luus
    Commented Jul 31, 2013 at 9:47
  • Here I am looking at this thread over and over; thinking no way, It can't be that.... Thank you so much!
    – MattCom
    Commented May 24, 2017 at 20:44
1

Try installing this as in an administrator command prompt. This worked for me.!

0
0

For me, the issue was as simple as just adding a closing quote around one of the textbox names in my CustomActionData string.

I was using the "Textboxes (A)" and "Textboxes (B)" windows in the User Interface section. A has 1 box, EDITA1, where I get the path to a file, and B has 2 boxes, EDITB1 and EDITB2, for some database parameters. My CustomActionData string looked like this:

/filepath="[EDITA1]" /host="[EDITB1] /port="[EDITB2]" 

It should have been:

/filepath="[EDITA1]" /host="[EDITB1]" /port="[EDITB2]" 

(closing quote on [EDITB1])

I used the Install override in my Installer class to get the values (i.e. string filepath = Context.Parameters["filepath"];) and used it to write them to an INI file for my app to use once installed. I put the "Primary output" under all of the phases in the Custom Actions GUI, but did nothing with the InstallerClass property (default: True) and only set the CustomActionData string on the Install one. I didn't even include override functions in my Installer class, since I was doing nothing that was custom in the other phases.

0

create your post install executable as you would a console app ex: "mypostinstallapp.exe".

install the "mypostinstallapp.exe" with your msi product. maybe put it with the Application Folder or a shared folder if you want to use it with multiple installs.

in the custom actions (rightclick the msi project and view custom actions) and add an action in the Commit section. assuming you want it to run towards the end.

then select your "mypostinstallapp.exe" from the actions view and in its properties set InstallerClass False.

what I do in "mypostinstallapp.exe" is look for a cmd file and run it as a process.

so i can add stuff to the cmd file and try to forget about the custom action process.

0

Make sure in the output properties you check installer class to false

enter image description here

0

You can set a register key to the installation path. Click on the Setup Project, View Register, and set the value as: [ProgramFiles64Folder][Manufacturer][ProductName].

Then you can create a Console App to get in to the register and take this information and run your program. Just need to add as a custom action on Commit the Console App you created.

0

In my case, I want to run a third party exe, what I had to do is to load the same exe during custom action "Install" and "Commit", and set the installer class property to "TRUE", so you don't have to import it as a primary output. I hope this helps other people

0

It is some kind of bug in the VisualStudio Installer Projects. Once put in the Install phase it started to work. Then when moved back to Commit phase, continues to work. But starting with the Commit it can't find it

-1

Try setting Installer class = false instead of true in the properties for your custom action. That fixed this problem for me.

1
  • 1. Not specific enough (which phase? Did you include events/override function in your Installer class for the phase you set to false?) 2. I'd say this had to have been some kind of edge case as it didn't work for me, and I have all of mine (for each phase) set to True with no issue.
    – vapcguy
    Commented Dec 1, 2016 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.