UpdateCheckInfo 类
定义
表示通过调用 CheckForDetailedUpdate() 获得的详细更新信息。Represents detailed update information obtained through a call to CheckForDetailedUpdate().
public ref class UpdateCheckInfo
public class UpdateCheckInfo
type UpdateCheckInfo = class
Public Class UpdateCheckInfo
- 继承
-
UpdateCheckInfo
示例
下面的代码示例使用 UpdateAvailable 来确定是否有新的应用程序更新,并 IsUpdateRequired 确定是否要求用户安装更新。The following code example uses UpdateAvailable to determine if there is a new application update, and IsUpdateRequired to determine whether to ask the user to install the update.
public:
void InstallUpdateSync()
{
if (ApplicationDeployment::IsNetworkDeployed)
{
bool isUpdateAvailable = false;
ApplicationDeployment^ appDeployment =
ApplicationDeployment::CurrentDeployment;
try
{
isUpdateAvailable = appDeployment->CheckForUpdate();
}
catch (InvalidOperationException^ ex)
{
MessageBox::Show("The update check failed. Error: {0}",
ex->Message);
return;
}
if (isUpdateAvailable)
{
try
{
appDeployment->Update();
MessageBox::Show(
"The application has been upgraded, and will now " +
"restart.");
Application::Restart();
}
catch (Exception^ ex)
{
MessageBox::Show("The update failed. Error: {0}",
ex->Message);
return;
}
}
}
}
private void InstallUpdateSyncWithInfo()
{
UpdateCheckInfo info = null;
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
try
{
info = ad.CheckForDetailedUpdate();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
return;
}
catch (InvalidDeploymentException ide)
{
MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
return;
}
catch (InvalidOperationException ioe)
{
MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
return;
}
if (info.UpdateAvailable)
{
Boolean doUpdate = true;
if (!info.IsUpdateRequired)
{
DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
if (!(DialogResult.OK == dr))
{
doUpdate = false;
}
}
else
{
// Display a message that the app MUST reboot. Display the minimum required version.
MessageBox.Show("This application has detected a mandatory update from your current " +
"version to version " + info.MinimumRequiredVersion.ToString() +
". The application will now install the update and restart.",
"Update Available", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
if (doUpdate)
{
try
{
ad.Update();
MessageBox.Show("The application has been upgraded, and will now restart.");
Application.Restart();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
return;
}
}
}
}
}
Private Sub InstallUpdateSyncWithInfo()
Dim info As UpdateCheckInfo = Nothing
If (ApplicationDeployment.IsNetworkDeployed) Then
Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
Try
info = AD.CheckForDetailedUpdate()
Catch dde As DeploymentDownloadException
MessageBox.Show("The new version of the application cannot be downloaded at this time. " + ControlChars.Lf & ControlChars.Lf & "Please check your network connection, or try again later. Error: " + dde.Message)
Return
Catch ioe As InvalidOperationException
MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " & ioe.Message)
Return
End Try
If (info.UpdateAvailable) Then
Dim doUpdate As Boolean = True
If (Not info.IsUpdateRequired) Then
Dim dr As DialogResult = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel)
If (Not System.Windows.Forms.DialogResult.OK = dr) Then
doUpdate = False
End If
Else
' Display a message that the app MUST reboot. Display the minimum required version.
MessageBox.Show("This application has detected a mandatory update from your current " & _
"version to version " & info.MinimumRequiredVersion.ToString() & _
". The application will now install the update and restart.", _
"Update Available", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End If
If (doUpdate) Then
Try
AD.Update()
MessageBox.Show("The application has been upgraded, and will now restart.")
Application.Restart()
Catch dde As DeploymentDownloadException
MessageBox.Show("Cannot install the latest version of the application. " & ControlChars.Lf & ControlChars.Lf & "Please check your network connection, or try again later.")
Return
End Try
End If
End If
End If
End Sub
注解
利用 UpdateCheckInfo ,你可以决定是否根据最新版本的相关信息升级 ClickOnce 应用程序。With UpdateCheckInfo, you can decide whether to upgrade your ClickOnce application based on information about the newest version. UpdateAvailable 将返回一个布尔值,指示是否有新的更新。UpdateAvailable will return a Boolean value indicating whether there is a new update at all. AvailableVersion属性提供了新版本的版本号,同时 MinimumRequiredVersion 提供了用户应该安装的最早版本。The AvailableVersion property provides the version number of the new version, while MinimumRequiredVersion provides the earliest version that the user should have installed. IsUpdateRequired 表示用户是否需要最新的可用更新。IsUpdateRequired expresses whether the latest available update is required of the user. 最后, UpdateSizeBytes 表示更新的总大小。Finally, UpdateSizeBytes expresses the total size of the update.
备注
<deploymentProvider>仅当应用程序设置为检查更新时,Visual Studio 才会将元素添加到清单中,因此你必须检查 应用程序是否应 在 "应用程序更新" 对话框的 "更新位置" 中检查更新或指定更新 URL。Visual Studio adds the <deploymentProvider> element to the manifest only if the application is set to check for updates, so you either have to check The application should check for updates or specify an update URL in Update location in the Application Updates Dialog Box.
属性
| AvailableVersion |
获取尚未安装的最新版本的版本号。Gets the version number of the latest uninstalled version. |
| IsUpdateRequired |
获取一个指示是否必须安装更新的值。Gets a value indicating whether the update must be installed. |
| MinimumRequiredVersion |
获取用户必须在计算机上安装的最低版本。Gets the minimum version that the user must have installed on the computer. |
| UpdateAvailable |
获取表示是否有未安装更新的值。Gets whether an uninstalled update is available. |
| UpdateSizeBytes |
获取可用更新的大小。Gets the size of the available update. |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |