Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 955
CJM Avatar asked Nov 09 '11 10:11

CJM


4 Answers

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.

like image 57
HoGo Avatar answered Nov 05 '22 02:11

HoGo


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.

like image 45
E.Z. Hart Avatar answered Nov 05 '22 00:11

E.Z. Hart


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.

like image 3
rmrrm Avatar answered Nov 05 '22 01:11

rmrrm


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.

like image 3
Elliot Chen Avatar answered Nov 05 '22 01:11

Elliot Chen