2

I am trying to retrieve a variable from WiX during an install. Here is the tests I have tried:

try
{
    string reqid = session["REQUESTID"];
    TraceLog.LogMessage("CustomAction => ReportUpgradeStatus: Straight Session is valid");
}
catch
{
    TraceLog.LogMessage("CustomAction => ReportUpgradeStatus: Straight Session is invalid");
}
try
{
    string reqid = session.CustomActionData["REQUESTID"];
    TraceLog.LogMessage("CustomAction => ReportUpgradeStatus: CustomActionData is valid");
}
catch
{
    TraceLog.LogMessage("CustomAction => ReportUpgradeStatus: CustomActionData is invalid");
}
try
{
    string reqid = session.GetProductProperty("REQUESTID");
    TraceLog.LogMessage("CustomAction => ReportUpgradeStatus: GetProductProperty is valid");
}
catch
{
    TraceLog.LogMessage("CustomAction => ReportUpgradeStatus: GetProductProperty is invalid");
}

I have some xml in Product.wxs as such:

<InstallExecuteSequence>
  <Custom Action="SetRequestIdProp" Before="InstallFiles" />  
  <Custom Action="ReportUpgradeStatusMVACA" After="SetRequestIdProp" />    
  <ScheduleReboot After="InstallFinalize"/>
</InstallExecuteSequence>

<Fragment>
  <Binary Id="CustomActionBinary" SourceFile="..\..\..\Bin\$(var.Configuration)\InstallationCA.CA.dll"/>    
  <Property Id="REQUESTID" Value="[REQUESTID]" />   
  <CustomAction Id="SetRequestIdProp" Property="REQUESTID" Value="[REQUESTID]" />    
  <CustomAction Id="ReportUpgradeStatusMVACA" 
              BinaryKey="CustomActionBinary" 
              DllEntry="ReportUpgradeStatusMVA" 
              Execute="commit" 
              Return="check" />
</Fragment>

How can I access the RequestID property? I seriously am at a loss here as I everything I try to make that value appear does nothing.

Any advice at all would be welcome.

EDIT: Problem resolved. Here is what I needed to do:

I changed my CustomAction to:

<CustomAction Id="SetRequestIdProp" 
              Property="ReportUpgradeStatusMVACA" 
              Value="REQUESTID=[REQUESTID];APPLIANCEID=[APPLIANCEID];SERVICEURL=[SERVICEURL];STATUSDIR=[STATUSDIR];AUTOUPDATE=[AUTOUPDATE]" />
<CustomAction Id="ReportUpgradeStatusMVACA" 
              BinaryKey="CustomActionBinary" 
              DllEntry="ReportUpgradeStatusMVA" 
              Execute="deferred" 
              Return="check"
              HideTarget="no" />

And my InstallExecuteSequence to:

<Custom Action="SetRequestIdProp" Before="ReportUpgradeStatusMVACA" />
<Custom Action="ReportUpgradeStatusMVACA" Before="InstallFinalize" />

I got the info using:

RequestId = Int32.Parse(session.CustomActionData["REQUESTID"]),
ApplianceId = Int32.Parse(session.CustomActionData["APPLIANCEID"]),
ServiceUrl = session.CustomActionData["SERVICEURL"],

Thanks for the help.

  • Where is the custom action that calls the code that retrieves session["REQUESTID"] ? I'd expect to see a CustomAction Id with a reference to the Dll that you added to the Binary table. – PhilDW Jan 19 '16 at 19:17
  • @PhilDW I edited it. – Random User Jan 19 '16 at 19:23

1 Answers1

2

Your custom action is a commit custom action (and I wonder why - it's unusual). That means it is also deferred, so you need to pass data via CustomActionData, and this seems to be a good explanation:

How to pass CustomActionData to a CustomAction using WiX?

Community
  • 1
  • 1
PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • Actually, I sort of inherited a huge mess and have never dealt with WiX previously (coming from a straight webapp background). Should I change this to deferred? – Random User Jan 19 '16 at 19:43
  • Commit custom actions can't be undone, that's the issue. The more normal approach is to make it a deferred custom action at a point in the execute sequence that makes sense, such as after InstallFiles if it depends on files being present, or earlier if it's conditioning the system for the install. There should also be a rollback custom action sequenced before your CA to undo whatever it does in case the install fails and rolls back, that's to restore the system to its earlier state as if the install had never started. – PhilDW Jan 20 '16 at 17:41