我正在尝试通过wxs文件将参数传递给WiX自定义操作。但我得到以下例外。
Calling custom action CustomActionRemoveFolder!CustomActionRemoveFolder.CustomActions.CreateScheduleTaskForRunningWatchdog
Creating the Scheduled Task for running watch dog
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Deployment.WindowsInstaller.InstallerException: Cannot access session details from a non-immediate custom action
at Microsoft.Deployment.WindowsInstaller.Session.ValidateSessionAccess()
at Microsoft.Deployment.WindowsInstaller.Session.get_Item(String property)
at CustomActionRemoveFolder.CustomActions.CreateScheduleTaskForRunningWatchdog(Session session)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction CA_scheduleTaskActionForWatchDog returned actual error code 1603 but will be translated to success due to continue marking
以下是我在wxs文件中声明和调用传递自定义操作的参数的方法。
<Property Id="UserName" Value="someDefaultValue" />
<CustomAction Id="SetUserName" Property="UserName" Value="[UserName]"/>
<InstallExecuteSequence>
<Custom Action="SetUserName" After="InstallInitialize" />
</InstallExecuteSequence>
我的自定义操作就像这样。
[CustomAction]
public static ActionResult CreateScheduleTaskForRunningWatchdog(Session session)
{
session.Log("The session value for username is " + session["UserName"]);
}
然后我正在运行msi
msiexec /i <installer-name> UserName="myName" /l*v log.txt
我在这里做错了什么?任何帮助将不胜感激。
答案 0 :(得分:1)
我认为异常表明:您无法通过延迟自定义操作访问此类属性(因为在延迟操作脚本开始执行时,这些属性已经很久了)。不要问为什么。 Windows Installer“由大多数开明的软件宇航员设计,由大多数糟糕的程序员实现”(c)不是我:)
你能做什么:
选项1:立即采取行动CreateScheduleTaskForRunningWatchdog
自定义操作。如果不可能/没有意义,请选择选项2.
选项2:请参阅:How to pass CustomActionData to a CustomAction using WiX?