简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM