我试图解决的问题是安装程序需要创建一个用户,该用户将被用作运行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确实显示调用了ValidateUsername
和ValidatePassword
动作。
如何安排自定义操作,以便在显示对话框时,属性已设置?