使用Wix#安装后更新app.config,>

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

我对Wix和wix#完全陌生,我试图在安装完成后更新app.config。我可以使用Wix Util扩展名util:XmlFile来实现它,但我希望通过wix#CustomDialog UI来实现。

下面是我尝试过的代码

var project = new ManagedProject("MyProduct",
                             new Dir(@"%ProgramFiles%\My Company\My Product",
                                 new File("Program.cs"),
                                 new File(@"myPath\App.config")),
                              new ElevatedManagedAction(CustomActions.OnInstall, Return.check, When.After, Step.InstallFiles, Condition.NOT_Installed)
                              {
                                  UsesProperties = "CONFIG_FILE=[INSTALLDIR]App.config"
                              });

        project.Load += Msi_Load;
        project.BeforeInstall += Msi_BeforeInstall;
        project.AfterInstall += Msi_AfterInstall;

创建CustomDialog并将其值设置为下一个之后的会话变量

void next_Click(object sender, EventArgs e)
    {
        MsiRuntime.Session["NAME"] = name.Text;
        Shell.GoNext();
    }

我能够在Msi_BeforeInstall中检索会话值,但是在这里app.config路径变得空,因为它没有复制到INSTALLDIR,并且当我尝试在Msi_AfterInstall上执行它时,我没有得到该会话可变属性

安装后,我也试图通过CustomAction做到这一点

 [CustomAction]
    public static ActionResult OnInstall(Session session)
    {

        return session.HandleErrors(() =>
        {
            string configFile = session.Property("INSTALLDIR") + "App.config";
            string userName = session.Property("NAME");
            UpdateAsAppConfig(configFile, userName);
        });
    }
    static public void UpdateAsAppConfig(string configFile,string name)
    {
        var config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configFile }, ConfigurationUserLevel.None);

        config.AppSettings.Settings["MyName"].Value = name;

        config.Save();
    }

但未获取会话变量属性。我真的很陌生,任何帮助将不胜感激。如果我做错了,或者安装后如何更新我的app.config,请帮助我。

谢谢。

我对Wix和wix#完全陌生,我试图在安装完成后更新app.config。我可以使用Wix Util扩展名util:XmlFile来实现它,但我希望它是...

c# wix wixsharp
1个回答
0
投票

我知道您的问题,AfterInstall

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