I am having trouble passing values between custom actions.
I have a Powershell script inline which is deferred and I want to pass a value from it to a C# Call function from attached native DLL, also deferred.
In an effort to ensure I have a property to set, I have created a custom action installer property whose name is in all caps (a public property?). In the below code I have called it MYPUBLICPROPERTY.
I have other values successfully being passed to the C# CA DLL but, for the life of me, I cannot figure how to get a value out of the Powershell script and into the action data of the call to the DLL.
Here's the powershell inline script I have:
Code: Select all
#Requires -version 3
Param( )
function Get-SomethingFromCommandLine {
[array] $cmdOutput = (my command)
Foreach ($placeholder IN $cmdOutput)
{
if ($var1 -match "thingy") {
# Set-Property -name "MYPUBLICPROPERTY" -value $var1
AI_SetMsiProperty MYPUBLICPROPERTY $var1
write-output $var1
}
}
}
Has anyone got a fix or a an approach I can try?
# Your code goes here
Get-SomethingFromCommandLine
Code: Select all
userData=[THISPROPWORKS1] [THISPROPWORKS2] [THISPROPWORKS3] [THISPROPWORKS4] [THISPROPWORKS5] [THISPROPWORKS6] [MYPUBLICPROPERTY]
I have tried using the session object from the C# custom action but apparently you can't access session variables from a Deferred Custom Action. The error I get is this;
Code: Select all
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> WixToolset.Dtf.WindowsInstaller.InstallerException: Cannot access session details from a non-immediate custom action
at WixToolset.Dtf.WindowsInstaller.Session.ValidateSessionAccess()
at WixToolset.Dtf.WindowsInstaller.Session.get_Item(String property)
at BradsCustomAction.CustomActions.CustomAction1(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 WixToolset.Dtf.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction BradsCustomAction.CA.dll returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 12:17:56: InstallExecute. Return value 3.