将用户输入从ManagedUI传递到WixSharp

时间:2016-03-02 16:17:32

标签: c# wix windows-installer 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中访问它。

2 个答案:

答案 0 :(得分:0)

在您的CustomAction中,它必须是:

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

公共属性名称必须是大写的(因为您要在对话框中设置要传递到安装序列中的属性,它需要公开)。

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

答案 1 :(得分:-2)

您需要通过命令提示发送对象。例如:

  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"];