【发布时间】:2017-01-20 07:45:40
【问题描述】:
在我的 WPF MVVM 应用程序中,我需要检查我的应用程序是否在安装后首先运行。我查看了 SO 中的一些示例,其中一个示例 - how to check whether my c# window app is running first time after installation 我发现以下代码,作者建议使用 UpgradeRequired:
// this must happen as soon as your program starts, before
// you do anything else with the settings
if (Properties.Settings.Default.UpgradeRequired)
{
// upgrade FIRST, before doing anything else with the settings
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
我在这里引用他的话:“我还建议在默认情况下为 true 的设置中添加一个“UpgradeRequired”布尔值......”但是当我尝试在我的 App.xaml.cs 文件中添加相同的代码时OnStartUp 事件处理程序然后发生以下错误:“设置不包含 UpgradeRequired 的定义”并且 UpgradeRequired 带有红色波浪线下划线。我以前没有遇到过 Properties.Settings 。所以我想知道:我应该将哪个程序集引用添加到我的应用程序中?我必须做什么才能访问 Properties.Settings.Default.UpgradeRequired?我们将不胜感激。
【问题讨论】:
标签: c# wpf application-settings