每次重新编译Windows应用程序时,都会更新AssemblyInfo.cs中的AssemblyVersion和AssemblyFileVersion。
当我的应用加载时,我会调用
Microsoft.Win32.RegistryKey key1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\MyFileType\\shell\\open\\command", true);
if (key1 == null)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\MyFileType\shell\open\command", null, "\"" + Application.ExecutablePath + "\"" + " \"%1\"");
flag = true;
}
Microsoft.Win32.RegistryKey key2 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\.abc", true);
if (key2 == null)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\.abc", null, "MyFileType");
flag = true;
}
Microsoft.Win32.RegistryKey key3 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\MyFileType\\DefaultIcon", true);
if (key3 == null)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\MyFileType\DefaultIcon", "", Application.ExecutablePath + ",2");
flag = true;
}
if (flag) SHChangeNotify(0x08000000, 0x0000, (IntPtr)null, (IntPtr)null);//SHCNE_ASSOCCHANGED SHCNF_IDLIST
每次我新编译的应用程序运行时,所有已保存的首选项都将消失,应用程序将恢复为默认首选项。
有什么想法会触发应用程序失去它的偏好吗?是因为我更新了版本号吗?如果是这样,我该如何解决这个问题?
是因为我重新插入了注册表项吗?
它可能是什么?
修改
首选项在应用程序运行的实例之间加载并保存正常,直到我执行新的构建...但无论如何这里是代码:
private void SaveSettings()
{
Properties.Settings.Default.useLastB = this.lastB.Checked;
Properties.Settings.Default.useLast2B = this.last2B.Checked;
Properties.Settings.Default.useLast3B = this.last3B.Checked;
Properties.Settings.Default.useLastSV = this.lastSV.Checked;
Properties.Settings.Default.useLast2SV = this.last2SV.Checked;
Properties.Settings.Default.useLast3SV = this.last3SV.Checked;
Properties.Settings.Default.showAverage = this.averageBox.Checked;
Properties.Settings.Default.showSum = this.sumBox.Checked;
Properties.Settings.Default.showNormalized = this.normalBox.Checked;
Properties.Settings.Default.pessimistic = this.pessimistic.Checked;
Properties.Settings.Default.realistic = this.realistic.Checked;
Properties.Settings.Default.optimistic = this.optimistic.Checked;
Properties.Settings.Default.useAinsley = this.ainsleyBox.Checked;
Properties.Settings.Default.useHandicapper = this.handicapperBox.Checked;
Properties.Settings.Default.useCustom = this.customBox.Checked;
Properties.Settings.Default.UseMorningLine = this.useMLBox.Checked;
Properties.Settings.Default.SolveAllRacesToSingleFile = this.singleFileCheckBox.Checked;
Properties.Settings.Default.Save();
}
private void LoadSettings()
{
Properties.Settings.Default.Reload();
this.lastB.Checked = Properties.Settings.Default.useLastB;
this.last2B.Checked = Properties.Settings.Default.useLast2B;
this.last3B.Checked = Properties.Settings.Default.useLast3B;
this.lastSV.Checked = Properties.Settings.Default.useLastSV;
this.last2SV.Checked = Properties.Settings.Default.useLast2SV;
this.last3SV.Checked = Properties.Settings.Default.useLast3SV;
this.averageBox.Checked = Properties.Settings.Default.showAverage;
this.sumBox.Checked = Properties.Settings.Default.showSum;
this.normalBox.Checked = Properties.Settings.Default.showNormalized;
this.pessimistic.Checked = Properties.Settings.Default.pessimistic;
this.realistic.Checked = Properties.Settings.Default.realistic;
this.optimistic.Checked = Properties.Settings.Default.optimistic;
this.handicapperBox.Checked = Properties.Settings.Default.useHandicapper;
this.ainsleyBox.Checked = Properties.Settings.Default.useAinsley;
this.customBox.Checked = Properties.Settings.Default.useCustom;
this.useMLBox.Checked = Properties.Settings.Default.UseMorningLine;
this.singleFileCheckBox.Checked = Properties.Settings.Default.SolveAllRacesToSingleFile;
}
由于
答案 0 :(得分:1)
应用程序设置的默认位置是此路径:
%USERPROFILE%\Local Settings\Application Data\<Company Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config
请注意,版本是路径的一部分 - 这就是为什么当您增加版本号时,看起来好像应用程序已丢失其设置。
您可以覆盖存储位置以删除路径中版本的依赖关系 - 请参阅Application Settings Architecture