Problems with creating custom action in VS2010

176 Views Asked by At

I'm trying to create a really simple custom action for a simple TEST, but when I run the Setup project it isn't working. Here is the code from the installer class. For now I just want to show a simple console message, to comprove that the code is executing.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;


namespace InstallerRemoveCM
{
[RunInstaller(true)]
public partial class InstallerRemoveCM : System.Configuration.Install.Installer
{
    public InstallerRemoveCM()
    {
        InitializeComponent();
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);

        Console.Write("aasdasdasda1");
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);

        Console.Write("aasdasdasda2");

    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
        Console.Write("aasdasdasda3");
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
        Console.Write("aasdasdasda4");
    }
}

}

I tried everything in the CustomActionData:

/target = [TARGETDIR]

/target = "[TARGETDIR]"

/target = "[TARGETDIR]\"

when the CustomActionData is empty, the installation runs till the end, but no console message is shown. Otherwise, if the CustomActionData has some of the parameters mentioned before, the install throw this message:

error 1001 exception occurred while initializing the installation

Well people, any help will be wellcome Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

Finally I change the code, with te objective of delete a directory ("C:\Program Files(x86)\ .... \cm") after the installation process. And now the commit part looks like this:

....

   [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
        var DirectorioInstalacao = Path.GetFullPath(Context.Parameters["targetdir"] + "/cm");
        File.Delete(DirectorioInstalacao.ToString());            
    }

... The CustomActionData has this: /targetdir="[TARGETDIR]\"

So now the instructions contained on the "Installer Class" are executed by the setup project, but an other error is showing up:

"Error 1001. An exception occurred during the installation configuration phase. This exception will be ignored and installation will continue. But the application might not work properly after the completion of installation. Access to the path "C: \ Program Files (x86) \ .... \ cm" was denied"

Or something like that, cos my OS is in Portuguese.

Please, Someone knows how to solve that problem?