在Windows Installer中,何时应该安排自定义操作以为属性生成值?

问题描述 投票:0回答:1

我试图解决的问题是安装程序需要创建一个用户,该用户将被用作运行Windows服务的身份。它适用于硬编码值。

我接下来要做的是通过生成加密密码来提供典型安装时的合理默认值。没有用户需要通过RDP或作为用户使用此凭证进行签名的用例。

我写了一个自定义动作来生成密码:

public class CustomActions
{
    [CustomAction]
    public static ActionResult GeneratePassword(Session session)
    {
        session.Log("Begin " + nameof(GeneratePassword));
        session["MY_PASSWORD"] = GenerateComplexPassword(24);
        session.Log("Completed " + nameof(GeneratePassword));
        return ActionResult.Success;
    }

    public static string GenerateComplexPassword(int length = 25)
    {
        // 
    }
}

Product.wxs中,二进制文件已注册并被引用。目前,我想查看生成的密码,因此未将其标记为隐藏或安全。一旦我开始工作,这将会到来。

<Wix>
    <Product>

        <Property Id="MY_USERNAME" Value="my-username" />
        <Property Id="MY_PASSWORD" Value=" " />  

        <Binary Id="MyCustomActions.CA.dll" src="$(var.CustomActions.TargetDir)\MyCustomActions.CA.dll" />

        <CustomAction Id="ValidateUsername"
                    Return="check"
                    Execute="immediate"
                    BinaryKey="MyCustomActions.CA.dll"
                    DllEntry="ValidateUsername" />

        <CustomAction Id="ValidatePassword"
                    Return="check"
                    Execute="immediate"
                    BinaryKey="MyCustomActions.CA.dll"
                    DllEntry="ValidatePassword" />

        <CustomAction Id="GeneratePassword"
                    Return="check"
                    Execute="immediate"
                    BinaryKey="MyCustomActions.CA.dll"
                    DllEntry="GeneratePassword" />

        <InstallExecuteSequence>
        <Custom Action="GeneratePassword" After="CostFinalize"></Custom>
        </InstallExecuteSequence>

    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <!-- omitted -->
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <!-- omitted -->
        </ComponentGroup>
    </Fragment>
</Wix>

当我运行安装程序时,日志中没有迹象表明属性MY_PASSWORD已由自定义操作更新,或者自定义操作已被调用。

但是,我的UI确实显示调用了ValidateUsernameValidatePassword动作。

如何安排自定义操作,以便在显示对话框时,属性已设置?

wix windows-installer custom-action wix3
1个回答
0
投票

您可以启用日志并查看如何评估Custom元素的条件。在您的情况下,内部文本为空的计算结果为false,因此操作不会执行。将内部文本设置为1以始终评估为true,或使用适合您需要的condition

© www.soinside.com 2019 - 2024. All rights reserved.