Application.UserAppDataRegistry和版本号

时间:2009-10-04 08:43:16

标签: .net

*或者:“%#%¤/ am我应该存储我的设置?”

为什么产品版本号包含在Application.UserAppDataRegistry注册表项中?我觉得这很烦人。

这是否只是鼓励开发人员永远坚持版本号1.0.0,因为更改版本号将导致用户放弃所有设置(除非付出额外的努力)?

如果我删除版本号,它当然会“更好”(我看到的方式),但框架仍然会创建带有版本号的注册表项。

我在监督什么?

5 个答案:

答案 0 :(得分:3)

他们为什么不提供: UserAppDataRegistryVersionSpecific和UserAppDataRegistryGlobal 然后开发人员可以决定他们更喜欢哪一个特定的项目/特定设置。

顺便说一下,有一个简单的解决方法:

string VersionIndependentRegKey {
  get {
    string versionDependent = System.Windows.Forms.Application.UserAppDataRegistry.Name;
    string versionIndependent = 
           versionDependent.Substring(0, versionDependent.LastIndexOf("\\"));
    return versionIndependent;
  }
}
object GetRegistryValue(string name, object defaultValue) {
  return Registry.GetValue(VersionIndependentRegKey, name, defaultValue);
}
object GetRegistryValue(string name) {
  return GetRegistryValue(name, null);
}
void SetRegistryValue(string name, object value, RegistryValueKind kind) {
  Registry.SetValue(VersionIndependentRegKey, name, value, kind);
}

答案 1 :(得分:1)

我认为这就是IsolatedStorage的用途。这是一些示例VB代码:

Public Shared Sub SaveGridLayout(ByVal grd As Infragistics.Win.UltraWinGrid.UltraGrid, ByVal sPrefix As String)
    Dim isf As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    Dim userDataFile As IsolatedStorageFileStream = New IsolatedStorageFileStream("ClearTrac" + sPrefix + ".dat", FileMode.Create, isf)
    grd.DisplayLayout.Save(userDataFile)
    userDataFile.Flush()
    userDataFile.Close()
End Sub

如果使用GetUserStoreForApplication,则它不是特定于版本的。

答案 2 :(得分:1)

这是我用来选择去掉版本的另一种方式:

if (Include_Version == true)
{
    rootRegKey = Application.UserAppDataRegistry;
}
else
{
    regKey = Application.UserAppDataRegistry.Name;
    rootRegKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(regKey.Substring(regKey.IndexOf("\\") + 1, regKey.LastIndexOf("\\") - regKey.IndexOf("\\") - 1), true);
}

答案 3 :(得分:0)

我认为版本号在那里,以便用户可以安装2个版本的应用程序并将它们并排运行。除此之外,我没有看到当版本号发生变化时丢失所有配置的理由。

就个人而言,我通常使用配置文件来保存配置信息并避免使用Windows注册表

答案 4 :(得分:0)

这允许您更改从一个版本存储到另一个版本的设置。如果版本1.0.0设置为“foo”,则在版本2.0.0中将1.0.0 / foo中的内容拆分为2.0.0 / foo和2.0.0 / bar,您仍然可以使用。您的安装程序/配置向导需要检查以前版本的设置分支,并将它们转换为新版本的设置。但请注意,您需要直接访问存储库以获取以前的版本。