【发布时间】:2017-05-15 03:09:47
【问题描述】:
我正在尝试通过 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
我在这里做错了什么?任何帮助将不胜感激。
【问题讨论】:
标签: c# wix windows-installer custom-action wix3.10