WiX 自定义操作提前结束
本文关键字:结束 操作 自定义 WiX | 更新日期: 2023-09-27 18:33:44
关于该主题有多个问题,我尝试了所有解决方案,但没有任何效果。
问题是它"确实"在安装了Visual Studio的机器上工作,但在其他PC上不起作用,因此很难调试。
自定义操作代码为:
[CustomAction]
public static ActionResult EnumerateSqlServers(Session session)
{
MessageBox.Show("start EnumerateSQLServers"); // the message is not showing.
ActionResult result;
DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
DataRow[] rows = dt.Select(string.Empty);//, "IsLocal desc, Name asc");
result = EnumSqlServersIntoComboBox(session, rows);
return result;
}
日志文件显示:
MSI (c) (2C:1C) [11:16:42:338]: Doing action: EnumerateSqlServersAction
Action 11:16:42: EnumerateSqlServersAction.
Action start 11:16:42: EnumerateSqlServersAction.
MSI (c) (2C:34) [11:16:42:385]: Invoking remote custom action. DLL: C:'Users'Test'AppData'Local'Temp'MSI9328.tmp, Entrypoint: EnumerateSqlServers
MSI (c) (2C:E8) [11:16:42:385]: Cloaking enabled.
MSI (c) (2C:E8) [11:16:42:385]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (2C:E8) [11:16:42:385]: Connected to service for CA interface.
Action ended 11:16:42: EnumerateSqlServersAction. Return value 3.
DEBUG: Error 2896: Executing action EnumerateSqlServersAction failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: EnumerateSqlServersAction, ,
Action ended 11:16:42: WelcomeDlg. Return value 3.
MSI (c) (2C:44) [11:16:42:635]: Doing action: FatalError
Action 11:16:42: FatalError.
Action start 11:16:42: FatalError.
Action 11:16:42: FatalError. Dialog created
Action ended 11:16:43: FatalError. Return value 2.
Action ended 11:16:43: INSTALL. Return value 3.
MSI (c) (2C:44) [11:16:43:370]: Destroying RemoteAPI object.
MSI (c) (2C:E8) [11:16:43:385]: Custom Action Manager thread ending.
我确实尝试了这样的空操作:
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
MessageBox.Show("");
return ActionResult.Success;
}
该操作有效!它显示一个空消息框。
编辑:经过大量测试,当我评论这一行时,我发现问题出在enumSQLServer上,它可以工作。
SmoApplication.EnumAvailableSqlServers(false);
使用详细 (/l*v) 设置记录安装程序。 我希望看到更多,包括 .NET 错误堆栈跟踪。 你可能缺少 Visual Studio 计算机上的依赖项,而不是干净的测试计算机上的依赖项。
最有可能缺少的依赖项是Microsoft.SqlServer.Smo.dll。 在自定义操作项目中,检查此引用是否设置为 CopyLocal = true,如果不是,则进行设置。
您是否已经尝试使用提升的权限运行安装程序(右键单击安装程序并选择"以管理员身份运行")?
据我所知,SmoApplication.EnumAvailableSqlServers(false)需要提升权限。
此外,请检查 .wxs 文件中的产品节点中自定义操作的定义。
以下定义应该有效:
<CustomAction
Id="EnumerateSqlServers"
BinaryKey="YOUR BINARY KEY"
DllEntry="EnumerateSqlServers"
Execute="immediate"
Return="check"/>
出于测试目的,还可以尝试以下操作:
<InstallUISequence>
<Custom Action="EnumerateSqlServers"
Before="ExecuteAction"
Overridable="yes">NOT Installed</Custom>
</InstallUISequence>
就我而言,这是在安装和卸载时发生的。
我们正在做的是加密作为参数传入的连接字符串。
安装
这失败了,因为我无法访问我们仍在处理的已安装配置文件。 我希望WiX更容易使用或有更好的文档。
卸载
由于我们没有任何自定义操作的条件,因此它在卸载期间也正在运行,并且在尝试加载不再存在的配置文件时失败。
解决方案:使用 NOT Installed AND NOT REMOVE
。如何仅在安装(而不是卸载)中执行自定义操作