请告诉我以下代码有什么问题?我可以在安装期间访问自定义操作数据,并将其值添加到会话自定义操作集合中。但是,在卸载期间,值对不在集合中。
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>
答案 0 :(得分:2)
MSI在安装后不会保留属性。阅读以下内容以获得良好的解决方案。
“WiX工具集的”记住属性“模式。” http://robmensching.com/blog/posts/2010/5/2/The-WiX-toolsets-Remember-Property-pattern
答案 1 :(得分:0)
您似乎只在安装ToolbarComponent时创建VSTOCustomAction_ToolbarName属性,因此当您尝试卸载时,永远不会创建VSTOCustomAction_ToolbarName属性,也不会设置。
解决此问题的一种方法是将工具栏名称保存在Windows注册表项上,而不是创建包含此值的属性,这样您就可以在尝试卸载产品时阅读它。