2010-03-20 108 views
3

我想在使用MSI安装程序安装我的WPF应用程序期间修改MyApp.exe.config文件中的userSettings部分(Properties.MyApp.Default)。在MSI安装过程中更改userSettings

我基本上实现了它这样的优秀文章: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,但这对我来说似乎是一种矫枉过正。

在此先感谢!

回答

0

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

您的exe文件的UserSettings部分包含新用户的默认值。

检查this question了解更多信息。

+0

在MSI安装期间保存用户设置时,它们被保存到C:\ Users \ Username \ AppData \ Local \ Microsoft_Corporation \ SomeHash \ Version(MSI version?)\ user.config。 – 2010-10-08 03:01:33