我正在尝试在使用 MSI 安装程序安装 WPF 应用程序期间修改 MyApp.exe.config 文件中的 userSettings 部分(Properties.MyApp.Default)。
我基本上像这篇优秀的文章一样实现了它: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 的文章,但这对我来说似乎有点矫枉过正。
提前致谢!