在 MSI 安装期间更改用户设置

发布于 2024-08-26 02:55:54 字数 1115 浏览 0 评论 0原文

我试图在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

物价感观 2024-09-02 02:55:54

用户设置保存在当前用户的本地文件夹中,通常类似于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文