3

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

提前致谢!

4

1 回答 1

0

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

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

检查此问题以获取更多信息。

于 2010-06-29T13:31:16.617 回答