Session 如何在Wix中安装和卸载期间访问会话自定义操作数据(属性)?

Session 如何在Wix中安装和卸载期间访问会话自定义操作数据(属性)?,session,wix,installation,uninstallation,Session,Wix,Installation,Uninstallation,你能告诉我下面的代码有什么问题吗?我能够在安装期间访问自定义操作数据,并将其值添加到会话自定义操作集合中。但是,在卸载I期间,值对不在集合中 public class CustomActions { //This action is only called during application install [CustomAction] public static ActionResult CreateToolbar(Session session)

你能告诉我下面的代码有什么问题吗?我能够在安装期间访问自定义操作数据,并将其值添加到会话自定义操作集合中。但是,在卸载I期间,值对不在集合中

public class CustomActions
{
    //This action is only called during application install
    [CustomAction]
    public static ActionResult CreateToolbar(Session session)       
    {
        //This works fine the value is properly sent from wix script
        //The variable toolbarName has the expected value
        string toolbarName = session["VSTOCustomAction_ToolbarName"];

        //Save the value for uninstaller
        session.CustomActionData.Add("VSTOCustomAction_ToolbarName", toolbarName);
        ...
    }

    //This action is only called during application uninstall
    [CustomAction]
    public static ActionResult RemoveToolbar(Session session)
    {
        //Get the toolbar name and remove it
        //Why does the following call return null?
        string toolbarName = session.CustomActionData["VSTOCustomAction_ToolbarName"];          
        ...
    }
}

Below is the WIX part that calls the above custom action.

<!-- Include the VSTO Custom action  -->
<Binary Id="VSTOCustomAction" SourceFile="CustomAction.CA.dll"/>
<CustomAction Id="CreateToolbar" BinaryKey="VSTOCustomAction" DllEntry="CreateToolbar" Execute="immediate"/>
<CustomAction Id="RemoveToolbar" BinaryKey="VSTOCustomAction" DllEntry="RemoveToolbar" Execute="immediate"/>
...
<CustomAction Id="PropertyAssign_ToolbarName" Property="VSTOCustomAction_ToolbarName" Value="MyToolBarName"/>
...
<!-- Modify the install sequence to call our custom action -->
<InstallExecuteSequence>
  <Custom Action="PropertyAssign_ToolbarName" Before="CreateToolbar"><![CDATA[(&ToolbarComponent = 3) AND NOT (!ToolbarComponent = 3)]]></Custom>
  <Custom Action="CreateToolbar" After="InstallFinalize"><![CDATA[(&ToolbarComponent = 3) AND NOT (!ToolbarComponent = 3)]]></Custom>
  <Custom Action="RemoveToolbar" After="InstallFinalize"><![CDATA[(&ToolbarComponent = 2) AND NOT (!ToolbarComponent = 2)]]></Custom>
</InstallExecuteSequence>   
公共类自定义操作
{
//此操作仅在应用程序安装期间调用
[海关行动]
公共静态ActionResult CreateToolbar(会话)
{
//如果值正确地从wix脚本发送,则此操作可以正常工作
//变量toolbarName具有预期值
string toolbarName=会话[“VSTOCustomAction_toolbarName”];
//保存卸载程序的值
session.CustomActionData.Add(“VSTOCustomAction_ToolbarName”,ToolbarName);
...
}
//此操作仅在应用程序卸载期间调用
[海关行动]
公共静态ActionResult RemoveToolbar(会话)
{
//获取工具栏名称并将其删除
//为什么下面的调用返回null?
字符串toolbarName=session.CustomActionData[“VSTOCustomAction_toolbarName”];
...
}
}
下面是调用上述自定义操作的WIX部分。
...
...

在安装ToolbarComponent时,您似乎只创建了VSTOCustomAction_ToolbarName属性,因此,当您尝试卸载时,VSTOCustomAction_ToolbarName属性从未创建或设置


解决此问题的一种方法是将工具栏名称保存在Windows注册表项上,而不是创建包含此值的属性,这样您可以在尝试卸载产品时读取它。

MSI在安装后不会保留属性。请阅读以下内容以获得一个好的解决方案

WiX工具集的“记住属性”模式