在 MSI 安装期间更改用户设置
我试图在使用 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 的文章,但这对我来说似乎有点过分了。
提前致谢!
I am trying to modify the userSettings section (Properties.MyApp.Default) in the MyApp.exe.config file during the installatio of my WPF application using an MSI installer.
I basically implemented it like in this excellent article: http://raquila.com/software/configure-app-config-application-settings-during-msi-install/
The difference is that I am not editing the appSettings but the userSettings section.
The problem is that although the code runs fine, the settings are not saved. After the installation the config file contains the old settings I use in my development environment.
I also tried to override OnAfterInstall(System.Collections.IDictionary stateSaver) instead of Install(System.Collections.IDictionary stateSaver) but it doesn't make a difference.
Here is the code that should change the config values:
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();
}
Any idea how to persist these changes? I already read about Wix but that seems like an overkill to me.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户设置保存在当前用户的本地文件夹中,通常类似于 C:\Users\Username\AppData\Local\Manufacturer\ApplicationName\Application.exe_StrongName\VersionNumber\user.settings 请注意,位置随应用程序版本而变化。
exe.config 的 UserSettings 部分包含新用户的默认值。
查看此问题了解更多信息。
User settings are saved in the current user's local folder, usually looks like C:\Users\Username\AppData\Local\Manufacturer\ApplicationName\Application.exe_StrongName\VersionNumber\user.settings Note that location changes with application versions.
UserSettings section of you exe.config contains default values for new users.
Check this question for more information.