WIX-从不调用自定义操作

问题描述

我是WIX的初学者,所以很有可能我搞砸了一些东西。任务似乎很简单,但是花了我几天的时间才能解决。 我确实需要在AppData / Local / {App + Version}中安装应用程序,其中App + Version必须具有以下格式:

Appv [主要]-[次要]

我正在阅读buildversion,我已经在C#中创建了CustomAction以“构建”我的安装文件名称。但是似乎永远不会调用自定义操作-INSTALLVERSIONFOLDER的认值不会改变。

那是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;
        }
    }
}

这就是具有目录的Fragment的代码,应在其中调用自定义操作:

<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>

一天结束时,应用程序将安装在认的Appdata / Local / testfolder中,而不是Appdata / Local / Appv1-0

我做错了什么?

解决方法

总体 :为了解决自定义操作问题,您需要设置适当的调试。这将帮助您解决甚至尚未遇到的许多问题。一个明显但重要的事实。另外,be careful with custom actions(针对不必要的自定义操作进行宣传)。

调试 :要为您的自定义操作设置进行调试,请点击以下链接:


一些其他有用的链接: