Defines generic WiX CustomAction.

This class does not contain any public constructor and is only to be used as a base class for deriving specialized CustomActions (e.g. ) or for declaring heterogeneous collections.

Наследование: WixEntity
Пример #1
0
    /// <summary>
    /// Builds msi for SonarQube installation
    /// </summary>
    static string BuildSonarQubeMsi()
    {
        var project = new Project(
            // Project name
            "SonarQube",

            // Default installation location.
            new Dir(BootstrapperConstants.DefaultInstallDir,
                    // File to be copied at installation location.
                    new Files(@"SonarQube\*.*"),
                    new WixSharp.File(new Id("sqljdbc64"), @"sqlauth\x64\sqljdbc_auth.dll")
        {
            Condition = "Msix64"
        },
                    new WixSharp.File(new Id("sqljdbc32"), @"sqlauth\x86\sqljdbc_auth.dll")
        {
            Condition = "NOT Msix64"
        }),

            new Dir(@"%Desktop%",
                    new ExeFileShortcut("SonarQube", string.Format(@"[INSTALLDIR]\{0}\bin\windows-x86-64\StartSonar.bat",
                                                                   BootstrapperConstants.SonarQubeProductName), "")
        {
            Condition        = new Condition("INSTALLSERVICE=\"NO\" AND Msix64"),
            WorkingDirectory = "[INSTALLDIR]"
        },
                    new ExeFileShortcut("SonarQube", string.Format(@"[INSTALLDIR]\{0}\bin\windows-x86-32\StartSonar.bat",
                                                                   BootstrapperConstants.SonarQubeProductName), "")
        {
            Condition        = new Condition("INSTALLSERVICE=\"NO\" AND NOT Msix64"),
            WorkingDirectory = "[INSTALLDIR]"
        }),

            // Files not to be installed but required to be carried with MSI. These files are unpacked
            // as and when required in user's temp folder and removed after usage.
            new Binary(new Id("LicenseFile"), @"Resources\License.rtf"),
            new Binary(new Id("SonarQubeLogo"), @"Resources\sonarqube.png"),
            new Binary(new Id("NtRights"), @"tools\ntrights.exe"),

            // Properties to be carried to Execute sequence from UI sequence with their values persisted.
            new Property("SETUPTYPE", SetupType.Evaluation),
            new Property("PORT", BootstrapperConstants.DefaultSonarQubePort),
            new Property("INSTANCE", BootstrapperConstants.DefaultSqlInstance),
            new Property("SQLAUTHTYPE", AuthenticationType.Sql),
            new Property("INSTALLSERVICE", "YES"),
            new Property("DATABASEUSERNAME", "sonarqube"),
            new Property("DATABASEPASSWORD", "sonarqube"),
            new Property("DATABASENAME", "sonarqubedb"),
            new Property("CURRENTLOGGEDINUSER", "default"),
            new Property("DBENGINE", DbEngine.H2),
            new Property("DBPORT", "1433")
            )
        {
            InstallScope = InstallScope.perMachine
        };

        project.GUID = new Guid("c2dd93c3-bf14-41ef-a87d-2b75a195b446");

        // Update InstallCustomActionsCount and UninstallCustomActionsCount in constants to
        // reflect the right progress during installation.
        // Progress is updated every time a message is received from a custom action.

        ElevatedManagedAction rollbackUnzipSonarQube = new ElevatedManagedAction(new Id("Action1.1"), "RollbackUnzipSonarQube", Return.ignore, When.After, Step.InstallFiles, Condition.NOT_Installed)
        {
            UsesProperties = "INSTALLDIR",
            Execute        = Execute.rollback
        };

        project.Actions = new WixSharp.Action[]
        {
            new ManagedAction(new Id("Action1.0"), "ChangeUserPrivilegesToLogOnAsService", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
            {
                Impersonate    = true,
                UsesProperties = "SETUPTYPE,CURRENTLOGGEDINUSER"
            },
            new SetPropertyAction(rollbackUnzipSonarQube.Id, "INSTALLDIR=[INSTALLDIR]", Return.check, When.After, Step.InstallInitialize, Condition.NOT_Installed),
            rollbackUnzipSonarQube,
            new ElevatedManagedAction(new Id("Action1.2"), "UnzipSonarQube", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed),
            new ElevatedManagedAction(new Id("Action1.3"), "SetSqlAuthInEnvironmentPath", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
            {
                Impersonate    = true,
                UsesProperties = "SETUPTYPE"
            },
            new ElevatedManagedAction(new Id("Action1.4"), "SetupSonarQubeConfiguration", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
            {
                UsesProperties = "SETUPTYPE,PORT,INSTANCE,SQLAUTHTYPE,INSTALLSERVICE,DATABASEUSERNAME,DATABASEPASSWORD,DATABASENAME,DBENGINE,DBPORT"
            }
        };

        ElevatedManagedAction rollbackInstallSonarQubeService = new ElevatedManagedAction(new Id("Action1.5"), "RollbackInstallSonarQubeService", Return.ignore, When.After, Step.InstallFiles, Condition.NOT_Installed)
        {
            UsesProperties = "INSTALLDIR",
            Execute        = Execute.rollback
        };

        WixSharp.Action[] actions = new WixSharp.Action[]
        {
            new SetPropertyAction(rollbackInstallSonarQubeService.Id, "INSTALLDIR=[INSTALLDIR]", Return.check, When.After, Step.InstallInitialize, Condition.NOT_Installed),
            rollbackInstallSonarQubeService,
            new ElevatedManagedAction(new Id("Action1.6"), "InstallSonarQubeService", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
            {
                UsesProperties = "SETUPTYPE,SQLAUTHTYPE,INSTALLSERVICE,CURRENTLOGGEDINUSER,DBENGINE,DBPORT,PORT",
                Condition      = new Condition("(NOT Installed AND INSTALLSERVICE=\"YES\")")
            },
            new ElevatedManagedAction(new Id("Action1.7"), "StartSonarBatch", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
            {
                UsesProperties = "INSTALLSERVICE",
                Condition      = new Condition("(NOT Installed AND INSTALLSERVICE=\"NO\")"),
                Impersonate    = true
            },
            new ElevatedManagedAction(new Id("Action1.8"), "UninstallSonarQubeService", Return.check, When.After, Step.RemoveFiles, Condition.Installed)
            {
                UsesProperties = "INSTALLSERVICE",
                Condition      = new Condition("(Installed AND INSTALLSERVICE=\"YES\")")
            },
            new ElevatedManagedAction(new Id("Action1.9"), "CleanSonarQubeInstallation", Return.check, When.After, Step.RemoveFiles, Condition.Installed)
        };

        project.Actions      = project.Actions.Concat <WixSharp.Action>(actions).ToArray <WixSharp.Action>();
        project.Version      = new Version(BootstrapperConstants.ProductVersion);
        project.MajorUpgrade = new MajorUpgrade()
        {
            DowngradeErrorMessage = "A later version of SonarQube is already installed on this machine",
            Schedule = UpgradeSchedule.afterInstallInitialize
        };

        string msi = project.BuildMsi();

        int exitCode = WixSharp.CommonTasks.Tasks.DigitalySign(msi,
                                                               "SonarQubeInstaller.pfx",
                                                               "http://timestamp.verisign.com/scripts/timstamp.dll",
                                                               "password");

        if (exitCode != 0)
        {
            Console.WriteLine("Could not sign the MSI file.");
        }
        else
        {
            Console.WriteLine("The MSI file was signed successfully.");
        }

        return(msi);
    }
    /// <summary>
    /// Builds msi for SonarQube installation
    /// </summary>
    static string BuildSonarQubeMsi()
    {
        var project = new Project(
                             // Project name
                             "SonarQube",

                             // Default installation location.
                             new Dir(BootstrapperConstants.DefaultInstallDir,
                                     // File to be copied at installation location.
                                     new Files(@"SonarQube\*.*"),
                                     new WixSharp.File(new Id("sqljdbc64"), @"sqlauth\x64\sqljdbc_auth.dll")
                                     {
                                          Condition = "Msix64"
                                     },
                                     new WixSharp.File(new Id("sqljdbc32"), @"sqlauth\x86\sqljdbc_auth.dll")
                                     {
                                         Condition = "NOT Msix64"
                                     }),

                             new Dir(@"%Desktop%",
                                     new ExeFileShortcut("SonarQube", string.Format(@"[INSTALLDIR]\{0}\bin\windows-x86-64\StartSonar.bat",
                                                                                    BootstrapperConstants.SonarQubeProductName), "")
                                     {
                                         Condition = new Condition("INSTALLSERVICE=\"NO\" AND Msix64"),
                                         WorkingDirectory = "[INSTALLDIR]"
                                     },
                                     new ExeFileShortcut("SonarQube", string.Format(@"[INSTALLDIR]\{0}\bin\windows-x86-32\StartSonar.bat",
                                                                                    BootstrapperConstants.SonarQubeProductName), "")
                                     {
                                         Condition = new Condition("INSTALLSERVICE=\"NO\" AND NOT Msix64"),
                                         WorkingDirectory = "[INSTALLDIR]"
                                     }),

                             // Files not to be installed but required to be carried with MSI. These files are unpacked
                             // as and when required in user's temp folder and removed after usage.
                             new Binary(new Id("LicenseFile"), @"Resources\License.rtf"),
                             new Binary(new Id("SonarQubeLogo"), @"Resources\sonarqube.png"),
                             new Binary(new Id("NtRights"), @"tools\ntrights.exe"),

                             // Properties to be carried to Execute sequence from UI sequence with their values persisted.
                             new Property("SETUPTYPE", SetupType.Evaluation),
                             new Property("PORT", BootstrapperConstants.DefaultSonarQubePort),
                             new Property("INSTANCE", BootstrapperConstants.DefaultSqlInstance),
                             new Property("SQLAUTHTYPE", AuthenticationType.Sql),
                             new Property("INSTALLSERVICE", "YES"),
                             new Property("DATABASEUSERNAME", "sonarqube"),
                             new Property("DATABASEPASSWORD", "sonarqube"),
                             new Property("DATABASENAME", "sonarqubedb"),
                             new Property("CURRENTLOGGEDINUSER", "default"),
                             new Property("DBENGINE", DbEngine.H2),
                             new Property("DBPORT", "1433")
                       )
        {
            InstallScope = InstallScope.perMachine
        };

        project.GUID = new Guid("c2dd93c3-bf14-41ef-a87d-2b75a195b446");

        // Update InstallCustomActionsCount and UninstallCustomActionsCount in constants to
        // reflect the right progress during installation.
        // Progress is updated every time a message is received from a custom action.

        ElevatedManagedAction rollbackUnzipSonarQube = new ElevatedManagedAction(new Id("Action1.1"), "RollbackUnzipSonarQube", Return.ignore, When.After, Step.InstallFiles, Condition.NOT_Installed)
                                                        {
                                                            UsesProperties = "INSTALLDIR",
                                                            Execute = Execute.rollback
                                                        };

        project.Actions = new WixSharp.Action[]
        {
                new ManagedAction(new Id("Action1.0"), "ChangeUserPrivilegesToLogOnAsService", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
                {
                    Impersonate = true,
                    UsesProperties = "SETUPTYPE,CURRENTLOGGEDINUSER"
                },
                new SetPropertyAction(rollbackUnzipSonarQube.Id, "INSTALLDIR=[INSTALLDIR]", Return.check, When.After, Step.InstallInitialize, Condition.NOT_Installed),
                rollbackUnzipSonarQube,
                new ElevatedManagedAction(new Id("Action1.2"), "UnzipSonarQube", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed),
                new ElevatedManagedAction(new Id("Action1.3"), "SetSqlAuthInEnvironmentPath", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
                {
                    Impersonate = true,
                    UsesProperties = "SETUPTYPE"
                },
                new ElevatedManagedAction(new Id("Action1.4"), "SetupSonarQubeConfiguration", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
                {
                    UsesProperties = "SETUPTYPE,PORT,INSTANCE,SQLAUTHTYPE,INSTALLSERVICE,DATABASEUSERNAME,DATABASEPASSWORD,DATABASENAME,DBENGINE,DBPORT"
                }
        };

        ElevatedManagedAction rollbackInstallSonarQubeService = new ElevatedManagedAction(new Id("Action1.5"), "RollbackInstallSonarQubeService", Return.ignore, When.After, Step.InstallFiles, Condition.NOT_Installed)
        {
            UsesProperties = "INSTALLDIR",
            Execute = Execute.rollback
        };

        WixSharp.Action[] actions = new WixSharp.Action[]
            {
                new SetPropertyAction(rollbackInstallSonarQubeService.Id, "INSTALLDIR=[INSTALLDIR]", Return.check, When.After, Step.InstallInitialize, Condition.NOT_Installed),
                rollbackInstallSonarQubeService,
                new ElevatedManagedAction(new Id("Action1.6"), "InstallSonarQubeService", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
                {
                    UsesProperties = "SETUPTYPE,SQLAUTHTYPE,INSTALLSERVICE,CURRENTLOGGEDINUSER,DBENGINE,DBPORT,PORT",
                    Condition = new Condition("(NOT Installed AND INSTALLSERVICE=\"YES\")")
                },
                new ElevatedManagedAction(new Id("Action1.7"), "StartSonarBatch", Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
                {
                    UsesProperties = "INSTALLSERVICE",
                    Condition = new Condition("(NOT Installed AND INSTALLSERVICE=\"NO\")"),
                    Impersonate = true
                },
                new ElevatedManagedAction(new Id("Action1.8"), "UninstallSonarQubeService", Return.check, When.After, Step.RemoveFiles, Condition.Installed)
                {
                    UsesProperties = "INSTALLSERVICE",
                    Condition = new Condition("(Installed AND INSTALLSERVICE=\"YES\")")
                },
                new ElevatedManagedAction(new Id("Action1.9"), "CleanSonarQubeInstallation", Return.check, When.After, Step.RemoveFiles, Condition.Installed)
            };

        project.Actions = project.Actions.Concat<WixSharp.Action>(actions).ToArray<WixSharp.Action>();
        project.Version = new Version(BootstrapperConstants.ProductVersion);
        project.MajorUpgrade = new MajorUpgrade()
        {
             DowngradeErrorMessage = "A later version of SonarQube is already installed on this machine",
             Schedule = UpgradeSchedule.afterInstallInitialize
        };

        string msi = project.BuildMsi();

        int exitCode = WixSharp.CommonTasks.Tasks.DigitalySign(msi,
                                                               "SonarQubeInstaller.pfx",
                                                               "http://timestamp.verisign.com/scripts/timstamp.dll",
                                                               "password");

        if (exitCode != 0)
        {
            Console.WriteLine("Could not sign the MSI file.");
        }
        else
        {
            Console.WriteLine("The MSI file was signed successfully.");
        }

        return msi;
    }