Im beginner in WIX, so its quite possible i messed up something. Task seems to be simple, but its taking me already days to solve. I do need to install application in AppData/Local/{App+Version}, where App+Version must have this format:
Appv[major]-[minor]
Im reading buildversion, and i have created CustomAction in C# to "build" my install folder name. But looks like custom action is never called - default value of INSTALLVERSIONFOLDER never changes.
Thats the code of CustomAction:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace CustomActions
{
public class CustomActions
{
[CustomAction]
public static ActionResult GetInstallFolder(Session session)
{
session.Log("Begin CustomAction1");
//buildversion in 1.0.0.0 format
string BuildVersion = session["INSTVERPROP"];
char[] chaArray = BuildVersion.ToCharArray();
//return name of the install folder in format: v[major]-[minor]
session["INSTALLVERSIONFOLDER"] = string.Format("Appv{0}-{1}", chaArray[0], chaArray[1]);
return ActionResult.Success;
}
}
}
And thats the code of Fragment with Directories, where custom action should be called:
<Fragment>
<Property Id="INSTVERPROP" Secure="yes" Value="$(var.BuildVersion)" />
<Property Id="INSTALLVERSIONFOLDER" Secure="yes" Value="testfolder" />
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Shortcut folder is a Start Menu Folder-->
<Directory Id="ProgramMenuFolder">
<Directory Id="InstallProgramMenuFolder" Name="!(loc.ProductNameFolder)" />
</Directory>
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="!(loc.ProductNameFolder)" />
</Directory>
</Directory>
<!-- Custom action to get correct InstallFolder name - from .exe build version-->
<Binary Id="CustomActionBinary"
SourceFile="$(var.CustomActions.TargetDir)$(var.CustomActions.TargetName).CA.dll" />
<CustomAction Id="GetInstallFolder" Impersonate="no" BinaryKey="CustomActionBinary" DllEntry="GetInstallFolder"
Return="check" />
<InstallExecuteSequence>
<Custom Action="GetInstallFolder" Before="CostFinalize"></Custom>
</InstallExecuteSequence>
<!--Or [AppDataFolder] - instalation in AppData/Roaming-->
<SetDirectory Id="INSTALLFOLDER" Value="[LocalAppDataFolder]\[INSTALLVERSIONFOLDER]"></SetDirectory>
</Fragment>
And at end of the day app is installed in default Appdata/Local/testfolder instead Appdata/Local/Appv1-0
What i did wrong ?