Settings.Default.Save() 在 Visual Studio 中调试应用程序时不会持续存在
Settings.Default.Save() does not persist when debugging app in Visual Studio
我有一些代码旨在确定设置是否已存在,如果存在则获取值。
exists = Settings.Default.Properties.OfType<SettingsProperty>().Any(p => p.Name == "LastOpenLocation");
if (!exists)
{
SettingsProperty lastOpenLocation = new SettingsProperty("LastOpenLocation");
lastOpenLocation.PropertyType = typeof(string);
lastOpenLocation.DefaultValue = casMate.OpenPath;
Settings.Default.Properties.Add(lastOpenLocation);
Settings.Default.Save();
}
else
{
Settings.Default.Properties["LastOpenLocation"].DefaultValue = casMate.OpenPath;
}
一切运行都很好,无一例外。下一次调试运行 上次保存的设置不会保留。在生产机器上安装应用程序之前,我想确保设置保持不变。问题是什么?为什么我的设置在调试 运行 秒之间没有保留?
这个问题的答案是...
A stack answer I couldn't find initially
我正在尝试在 运行 时间创建一个新设置。只能在设计时创建新设置。
我有一些代码旨在确定设置是否已存在,如果存在则获取值。
exists = Settings.Default.Properties.OfType<SettingsProperty>().Any(p => p.Name == "LastOpenLocation");
if (!exists)
{
SettingsProperty lastOpenLocation = new SettingsProperty("LastOpenLocation");
lastOpenLocation.PropertyType = typeof(string);
lastOpenLocation.DefaultValue = casMate.OpenPath;
Settings.Default.Properties.Add(lastOpenLocation);
Settings.Default.Save();
}
else
{
Settings.Default.Properties["LastOpenLocation"].DefaultValue = casMate.OpenPath;
}
一切运行都很好,无一例外。下一次调试运行 上次保存的设置不会保留。在生产机器上安装应用程序之前,我想确保设置保持不变。问题是什么?为什么我的设置在调试 运行 秒之间没有保留?
这个问题的答案是... A stack answer I couldn't find initially
我正在尝试在 运行 时间创建一个新设置。只能在设计时创建新设置。