1

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 ?

mrsilesia
  • 21
  • 2
  • [WiX managed code dustom action overview](https://stackoverflow.com/a/60384739/129130) and [debugging custom actions](https://stackoverflow.com/a/52880033/129130) (and a [video on CA debugging](https://www.youtube.com/watch?v=ayeBB97_NwA)). And throwing in [this somewhat hodgepodge link collection for WiX and MSI issues](https://stackoverflow.com/questions/25004226/msi-vs-nuget-packages-which-are-is-better-for-continuous-delivery/25005864#25005864). – Stein Åsmul Nov 10 '20 at 03:40
  • Thank you Stein ! Following the "debug" instructions i found out that Custom Action was actually executed, but by some reason new folder name was not assigned correctly to INSTALLFOLDER. What i did ? Just restarted my machine (actually got tired and went to sleep). At morning it works... magic ! – mrsilesia Nov 10 '20 at 16:18
  • Great, I have quickly adapted an answer below for others who seek the same material. I added [a section on using message boxes from C#](https://stackoverflow.com/a/52880033/129130) to the debugging links below. That way you can see if the action runs at all with ease. – Stein Åsmul Nov 10 '20 at 20:24

1 Answers1

1

Overall: In order to resolve custom action problems you need to set up proper debugging. This will help with many issues that you haven't even faced yet. An obvious, but important fact. Also, be careful with custom actions (propaganda against unnecessary custom actions).

Debugging: To get debugging for your custom actions set up, please follow these links:


Some other useful links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164