为什么我在WIX中的托管自定义操作中获取SourceDir的空白值?

时间:2014-05-21 04:12:44

标签: c# .net wix windows-installer custom-action

以下是我正在使用的Product.wxs的代码:

<Product Id="*" Name="abc" Language="1033" Version="1.0.0.0" Manufacturer="def" UpgradeCode="2b75c560-783e-4688-9a02-da09bf986597">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />

    <Binary Id="myCustomActionsDLL" SourceFile="..\SetupConfiguration\bin\debug\SetupConfiguration.CA.dll" />
    <CustomAction Id="SetProperty" Execute="immediate"
                        Property="CA_myCustomAction"
                        Value="InstallDir=[MergeRedirectFolder];SourceDir=[SourceDir]" />
    <CustomAction Id="CA_myCustomAction"
        BinaryKey="myCustomActionsDLL"
        DllEntry="SetABCConfiguration"
        Execute="deferred" Impersonate="no"
        Return="check" />

    <InstallExecuteSequence>
      <Custom Action="SetProperty" After="InstallInitialize">Not Installed</Custom>
      <Custom Action="CA_myCustomAction" Before="InstallFinalize">Not Installed</Custom>
    </InstallExecuteSequence>

    <Feature Id="ProductFeature" Title="abc" Level="1">
      <ComponentGroupRef Id="ABCGroup" />
    </Feature>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="def" Name="def">
          <Directory Id="dirFC83E07AC2C77525961486C88A01C277" Name="ABC">
            <Directory Id="MergeRedirectFolder"/>
          </Directory>
          </Directory>
      </Directory>
    </Directory>
  </Fragment>

[CustomAction]
public static ActionResult SetABCConfiguration(Session session)
{
    string strSourceFolder = session.CustomActionData["SourceDir"]; // returning blank value
    string strWebGeniePhyPath = session.CustomActionData["InstallDir"]; // returning correct value
}

我故意遗漏了组件ABCGroup的代码,它只包含一个热量收集目录,这是一个很长的列表。

请帮忙。

2 个答案:

答案 0 :(得分:1)

SourceDir propertyResolveSource Action设置。默认情况下,WiX不会创建ResolveSource操作,您必须使用ResolveSource Element将其添加到序列中。

答案 1 :(得分:0)

我只是通过尝试来找到解决方案:

只需更改以下行:

  <Custom Action="SetProperty" After="InstallInitialize">Not Installed</Custom>

到这一行:

  <Custom Action="SetProperty" After="CreateFolders">Not Installed</Custom>

它有效。

我不知道为什么这种更改有效,因为有问题的代码在合并模块中而不是在主Product.wxs文件中时有效。