CJM
CJM

Reputation: 12016

Custom Action - Error 1001: Could not find file myApp.InstallState

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?

Upvotes: 36

Views: 36666

Answers (12)

altair
altair

Reputation: 141

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

Upvotes: 0

mslugx
mslugx

Reputation: 814

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

Upvotes: 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.

Upvotes: 0

DD Developer
DD Developer

Reputation: 1

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

enter image description here

Upvotes: 0

dcarl661
dcarl661

Reputation: 322

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.

Upvotes: 0

vapcguy
vapcguy

Reputation: 7537

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.

Upvotes: 0

user1828022
user1828022

Reputation: 9

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

Upvotes: -1

Jason
Jason

Reputation: 51

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

Upvotes: 2

Elliot Chen
Elliot Chen

Reputation: 378

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.

Upvotes: 3

HoGo
HoGo

Reputation: 587

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.

Upvotes: 55

E.Z. Hart
E.Z. Hart

Reputation: 5747

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.

Upvotes: 19

Cosmin
Cosmin

Reputation: 21416

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.

Upvotes: 3

Related Questions