【问题标题】:Cancelling Installer from Installing setup in Visual Studio Setup在 Visual Studio 安装程序中取消安装程序
【发布时间】:2014-05-15 10:17:33
【问题描述】:

我有一个安装程序类,它在安装时从用户那里获取价值。现在根据我的要求,如果提供的值不正确,我必须取消安装,但我不知道如何获得它。 .

这是我的 installer.cs 文件..

 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);

        }
    }

尽管Rollback(stateSaver); 我的设置已安装..

请帮帮我..

【问题讨论】:

  • 我相信,抛出异常应该会导致 Rollback() 被调用。你不应该自己称呼它。
  • @Damien_The_Unbeliever throw new InstallException("Your input is wrong""); 像这样我必须使用

标签: c# visual-studio-2010 installation setup-project


【解决方案1】:

只需调用 InstallException 即可进行回滚。这是通常的方式并且它有效,所以如果它没有那么其他事情正在发生。

您应该考虑使用另一种工具,让您在输入数据时对其进行验证。 VS 自定义操作始终在安装完所有文件后运行,因此基本上您是在安装整个应用程序,然后将其回滚,而不是使用允许您验证何时输入的 MSI 构建工具。

【讨论】:

    猜你喜欢
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多