我想在使用MSI安装程序安装我的WPF应用程序期间修改MyApp.exe.config文件中的userSettings部分(Properties.MyApp.Default)。在MSI安装过程中更改userSettings
我基本上实现了它这样的优秀文章:http://raquila.com/software/configure-app-config-application-settings-during-msi-install/
不同的是,我不是编辑的appSettings但userSettings部分。
问题是,虽然代码运行正常,但不会保存设置。安装后,配置文件包含我在开发环境中使用的旧设置。 我也尝试重写OnAfterInstall(System.Collections.IDictionary stateSaver)而不是Install(System.Collections.IDictionary stateSaver),但它没有区别。
这里是一个要改变的配置值的代码:
protected override void OnAfterInstall(IDictionary savedState)
{
base.OnAfterInstall(savedState);
string targetDirectory = Context.Parameters["targetdir"];
string tvdbAccountID = Context.Parameters["TVDBACCID"];
// read other config elements...
Properties.Settings.Default.Tvdb_AccountIdentifier = tvdbAccountID;
// set other config elements
Properties.Settings.Default.Save();
}
不知道如何保存这些变化?我已经阅读了Wix,但这对我来说似乎是一种矫枉过正。
在此先感谢!
在MSI安装期间保存用户设置时,它们被保存到C:\ Users \ Username \ AppData \ Local \ Microsoft_Corporation \ SomeHash \ Version(MSI version?)\ user.config。 – 2010-10-08 03:01:33