user3617097
user3617097

Reputation: 115

Cancelling Installer from Installing setup in Visual Studio Setup

I have a installer class which is taking a vale from the user at the time of installation.Now as per my requirement if the value provided is not correct i have to cancel the installation but i am not getting how to get this ..

Here is my installer.cs file..

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

        // Retrieve configuration settings
        string targetSite = Context.Parameters["targetsite"];
        string targetVDir = Context.Parameters["targetvdir"];
        string targetDirectory = Context.Parameters["targetdir"];

        string value = Context.Parameters["value"];

        string connectionstring = Context.Parameters["db"];

        if (targetSite == null)
            throw new InstallException("IIS Site Name Not Specified!");

        if (targetSite.StartsWith("/LM/"))
            targetSite = targetSite.Substring(4);

        if (connectionstring == null)
            throw new InstallException("You did not specify a database to use!");

        if (value.Equals("123"))
        {

            RegisterScriptMaps(targetSite, targetVDir);
            ConfigureDatabase(targetSite, targetVDir, connectionstring);
        }

        else {

            Rollback(stateSaver);

        }
    }

Inspite of Rollback(stateSaver); my setup gets installed..

Please help me..

Upvotes: 0

Views: 1504

Answers (1)

PhilDW
PhilDW

Reputation: 20800

Just calling InstallException will do the rollback. That's the usual way and it works, so if it doesn't then something else is going on.

You should think about using another tool that lets you validate the data when it gets entered. VS custom actions always run after all the files have been installed, so basically you're installing the entire app and then rolling it back rather than using an MSI build tool that lets you validate when it's entered.

Upvotes: 1

Related Questions