在MSI安装期间更改userSettings

时间:2010-03-20 15:07:41

标签: wpf windows-installer setup-deployment settings

我正在尝试使用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的内容,但这对我来说似乎有些过分。

提前致谢!

1 个答案:

答案 0 :(得分:0)

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

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

查看this question了解详情。

相关问题