Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

c# - Why I am getting blank value for SourceDir in a managed Custom Action in WIX?

Here is the code for the Product.wxs I am using:

<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="..SetupConfigurationindebugSetupConfiguration.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
}

I have deliberately left out the code for component ABCGroup, it just contains a heat harvested directory, which is a long list.

Please help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The SourceDir property is set by the ResolveSource Action. WiX doesn't author the ResolveSource action by default, you have to add it to your sequence using the ResolveSource Element.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...