2017-05-15 9 views
0

wxs 파일을 통해 WiX 사용자 지정 작업에 매개 변수를 전달하려고합니다. 그러나 나는 아래 예외를 얻고있다.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"]); 
} 

은 그럼 내가 잘못 여기서 뭐하는 거지

msiexec /i <installer-name> UserName="myName" /l*v log.txt 

로 MSI를 실행하고? 어떤 도움이라도 대단히 감사 할 것입니다.

답변

1

예외가 있다고 생각합니다 : deferred 사용자 지정 작업 (지연된 작업 스크립트가 실행되기 시작할 때까지 오랫동안 작동하지 않기 때문에)과 같은 속성에 액세스 할 수 없습니다. 이유를 묻지 마십시오. Windows 설치는 "대부분의 계몽 소프트웨어 우주 비행사에 의해 설계 및 가장 형편없는 코더에 의해 구현되었다"(C)

당신이 할 수있는 걸 :)하지 :

옵션 1 : 행동 CreateScheduleTaskForRunningWatchdog 즉시 사용자 지정 작업을합니다. 수없는 경우 /, 이해가 옵션 2

옵션 2 이동하지 않습니다를 참조하십시오 : 즉시에 사용자 지정 작업 CreateScheduleTaskForRunningWatchdog을 변경 한 후 How to pass CustomActionData to a CustomAction using WiX?

+0

, 그 예외는 사라졌다. 하지만 지금 사용자 지정 작업 CreateScheduleTaskForRunningWatchdog 내부 세션 [ "UserName"]에 대한 기본값이 나타납니다. 다른 문제가 있습니까? – mayooran

+0

당신은 아마 적절한 순서를 설정해야합니다. 먼저 속성을 설정하고 가져옵니다. ExecuteSequence ... "After"특성을 사용합니다. 즉, CreateScheduleTaskForRunningWatchdog는 SetUserName 뒤에 있어야합니다. – Nikolay

+0

mayooran