在CustomAction

时间:2016-01-19 17:43:03

标签: c# wix

我正在尝试在安装期间从WiX检索变量。这是我尝试过的测试:

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");
}

我在Product.wxs中有一些xml:

<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>

如何访问RequestID属性?我在这里感到很茫然,因为我试图让这个价值出现的一切都没有。

欢迎任何建议。

编辑:问题已解决。这是我需要做的:

我将CustomAction更改为:

<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" />

我的InstallExecuteSequence:

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

我使用以下信息获取信息:

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您的自定义操作是提交自定义操作(我想知道为什么 - 它不常见)。这意味着它也是延迟的,所以你需要通过CustomActionData传递数据,这似乎是一个很好的解释:

How to pass CustomActionData to a CustomAction using WiX?