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

发布于 2024-09-12 04:25:00 字数 2139 浏览 5 评论 0原文

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

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>   

Can you please tell me what is wrong with the following code? I am able to access the custom action data during install and I add their values to session custom action collection. However, during uninstall I the value pairs are not in the collection.

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>   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰沐子 2024-09-19 04:25:00

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

“WiX 工具集的‘记住属性’模式。”
http://robmensching.com/博客/帖子/2010/5/2/The-WiX-toolsets-Remember-Property-pattern

MSI doesn't persist properties after an install. Read the following for a good solution.

"The WiX toolset's "Remember Property" pattern."
http://robmensching.com/blog/posts/2010/5/2/The-WiX-toolsets-Remember-Property-pattern

撩人痒 2024-09-19 04:25:00

看来您只是在安装 ToolbarComponent 时创建 VSTOCustomAction_ToolbarName 属性,因此当您尝试卸载时,永远不会创建或设置 VSTOCustomAction_ToolbarName 属性。

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

It seems that you are only creating the VSTOCustomAction_ToolbarName property when installing the ToolbarComponent, so when you try to uninstall, the VSTOCustomAction_ToolbarName property is never created, nor set.

One way to solve this problem could be saving the Toolbar Name on a Windows registry key instead of creating a property to contain this value, so you can read it while trying to uninstall your product.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文