【问题标题】:Change userSettings during MSI installation在 MSI 安装期间更改用户设置
【发布时间】:2011-01-29 19:46:00
【问题描述】:

在使用 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 的文章,但这对我来说似乎有点矫枉过正。

提前致谢!

【问题讨论】:

    标签: wpf windows-installer setup-deployment settings


    【解决方案1】:

    用户设置保存在当前用户的本地文件夹中,通常看起来像 C:\Users\Username\AppData\Local\Manufacturer\ApplicationName\Application.exe_StrongName\VersionNumber\user.settings 注意位置随应用程序版本而变化。

    exe.config 的 UserSettings 部分包含新用户的默认值。

    查看this question了解更多信息。

    【讨论】:

    • 在 MSI 安装期间保存用户设置时,它们会保存到 C:\Users\Username\AppData\Local\Microsoft_Corporation\SomeHash\Version(MSI 版本?)\user.config。跨度>
    猜你喜欢
    • 1970-01-01
    • 2012-02-24
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 2014-10-22
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多