问题
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="..\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
}
I have deliberately left out the code for component ABCGroup
, it just contains a heat harvested directory, which is a long list.
Please help.
回答1:
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.
回答2:
I have found the solution myself by just trying things:
Just change the following line:
<Custom Action="SetProperty" After="InstallInitialize">Not Installed</Custom>
to this line:
<Custom Action="SetProperty" After="CreateFolders">Not Installed</Custom>
and it works.
I don't know why this change works, because the code in question was working when it was in a merge module rather than in the main Product.wxs
file.
来源:https://stackoverflow.com/questions/23773840/why-i-am-getting-blank-value-for-sourcedir-in-a-managed-custom-action-in-wix