简体   繁体   English

Wix工具集:如何在自定义操作中确定安装模式

[英]Wix Toolset: How to determine installation mode in a Custom Action

Is there any chance to check the type of the installation mode in a Custom Action. 是否有机会在“自定义操作”中检查安装模式的类型。 I want to create one Custom Action for both Install and Uninstall modes, but perform different logic based on the mode. 我想为安装和卸载模式创建一个自定义操作,但是根据该模式执行不同的逻辑。

Something like: 就像是:

public static ActionResult CreateBackUpAction(Session session)
{
    //if (InstallType == "Install")
    //{
    //  BackUpFiles();
    //}
    //else if (InstallType == "Remove")
    //{
    //    DeleteBackUpFiles();
    //}

    return ActionResult.Success;
}

I know that ideally I should have 2 different action for both cases, but I would like to minimize amount of lines in the installer's sources. 我知道理想情况下,两种情况下我应该有两种不同的操作,但是我想减少安装程序源中的行数。

You should be able to use the session object's Item to get the property values of the current install. 您应该能够使用会话对象的Item获取当前安装的属性值。 The value of session["REMOVE"] (it should be "ALL") will tell you it's an uninstall, and the value of session["Installed"] if it's a fresh install. session [“ REMOVE”](应该为“ ALL”)的值将告诉您这是卸载,而session [“ Installed”]的值则是全新安装。

However, yes, you should use these types of conditions to call separate custom actions for a few reasons: 但是,是的,出于以下几个原因,您应该使用以下类型的条件来调用单独的自定义操作:

  1. It means that you don't need to worry about deferred custom actions and properties and need to use the deferred custom action model with CustomActionData because Windows will take care of it. 这意味着您不必担心延迟的自定义操作和属性,并且不需要将延迟的自定义操作模型与CustomActionData一起使用,因为Windows会处理它。 Using session ["REMOVE"], for example, may not work if the custom action is deferred. 例如,如果推迟了自定义操作,则可能无法使用会话[“ REMOVE”]。 This documentation doesn't say that the Installed or REMOVE properties are available in deferred custom actions, so you'll be using session.CustomActionData with another custom action to set it. 该文档没有说明在延迟的自定义操作中可以使用Installed或REMOVE属性,因此您将使用session.CustomActionData和另一个自定义操作来对其进行设置。

https://msdn.microsoft.com/en-us/library/windows/desktop/aa370543(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa370543(v=vs.85).aspx

  1. A managed code custom action call to an out of process method isn't cheap. 对进程外方法的托管代码自定义操作调用并不便宜。 You'll be calling into all that mechanism and returning, when you could just use Not Installed as a condition. 当您可以使用“未安装”作为条件时,您将调用所有该机制并返回。 If you have features that can be altered, or a repair happens then you will be calling again and returning again (having done nothing) if you have no conditions on the calls. 如果您具有可以更改的功能或维修,那么如果您在通话中没有任何条件,则将再次呼叫并再次返回(什么也没做)。

  2. You don't have a good way to deal with rollback, because (for example) if the uninstall fails and rolls back I assume you would actually prefer to keep those backed-up files that you are deleting with your code. 您没有应对回滚的好方法,因为(例如)如果卸载失败并回滚,我认为您实际上更希望保留要用代码删除的那些备份文件。 In other words, it's not clear what you want to do with those backed-up files in the event of an install failure, uninstall failure, rollbacks, and when you are upgrading an existing installed product. 换句话说,在安装失败,卸载失败,回滚以及升级现有已安装产品的情况下,不清楚要如何处理这些备份文件。

It's also my opinion that several smaller focused custom actions that do one thing are easier to deal with than one large piece of code that is full of conditions. 我也认为,比起一大堆有条件的大型代码,执行某件事的几个较小的,集中的自定义操作更易于处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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