将用户输入从 ManagedUI 传递到 WixSharp 中的 CustomAction

Pass user input from ManagedUI to CustomAction in WixSharp

这是我在 ManagedUI 中填充会话的代码,来自:

void next_Click(object sender, EventArgs e)
{
    MsiRuntime.Session["PASSWORD"] = password.Text;
    MsiRuntime.Session["DOMAIN"] = domain.Text;

    Shell.GoNext();
}

这是我的 CustomAction:

public class CustomActions
{
    [CustomAction]
    public static ActionResult InstallService(Session session)
    {
        MessageBox.Show(session["Password"]); // always shows an empty message
        return ActtionResult.Success;
    }
    ...

我还是没弄明白我的代码有什么问题?我已将数据填充到会话中,但无法在 CustomAction 中访问它。

您需要通过命令发送对象 promp.For 示例:

  using (var p = new Process())
                {
                    var info = new ProcessStartInfo
                    {
                        WindowStyle = ProcessWindowStyle.Hidden,
                        FileName = @"C:\Windows\System32\cmd.exe",
                        Arguments = string.Format("/c msiexec /i \"{0}\{6}.msi\" PATHNAME=\"{0}\" SSLCERTPATH=\"{1}\"" +
                        " MSINEWINSTANCE=1 TRANSFORMS=\":{2}\" USERPATH={3} ENVIRONMENTPATH={4} SSLCERTPASS=\"{5}\" /L*v \"{0}\{6}Log.txt\""
                        , XmlSettings.EnvironmentFolderPath, FindCertificates.SslCertPath, environment, XmlSettings.IisUserFolderPath,
                        XmlSettings.EnvironmentFolderPath, FindCertificates.SslCertPass, msiName),
                        UseShellExecute = false,
                        CreateNoWindow = true
                    };
                    p.StartInfo = info;
                    p.Start();
                    p.WaitForExit();
                }

然后在你的wxs项目中:

  <Property Id="SITEPHYSPATH"  Hidden="yes"/>
    <Property Id="USERPATH"  Hidden="yes"/>
    <Property Id="ENVIRONMENTPATH"  Hidden="yes"/>
    <Property Id="THUMBPRINT"  Hidden="yes"/>
    <Property Id="PATHNAME" Hidden="yes" />

最后在自定义操作中设置您的对象:

var thumbprint = session["THUMBPRINT"];

在您的 CustomAction 中,它需要是:

MessageBox.Show(session["PASSWORD"]); //upper case "PASSWORD" instead of "Password"

Public 属性 名称需要大写(因为您要在要传递到安装序列的对话框中设置 属性,所以它需要是public).

http://www.advancedinstaller.com/user-guide/properties.html