【发布时间】:2020-04-22 03:40:00
【问题描述】:
我对 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,请帮助我。
谢谢。
【问题讨论】: