c# - 如何:使用 ClickOnce 部署 API 以编程方式检查应用程序更新
问题描述
我有一个简单的应用程序,其中有一个搜索更新的按钮,此按钮触发以下方法
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 void button1_Click(object sender, EventArgs e)
{
InstallUpdateSyncWithInfo();
}
在它说的方法的第一个 if
if (ApplicationDeployment.IsNetworkDeployed)
IsNetworkDeployed 说:获取一个值,表示当前应用程序是否是 ClickOnce 应用程序
发生的事情是 IsNetworkDeployed 总是让我误以为
如果输入为false,则立即退出该方法
在我已经放了一个新版本的属性中,我放了发布将到达的路由,必须进行另一个配置,以便当前应用程序是 ClickOnce?
解决方案
推荐阅读
- elixir - 在 phoenix 中测试 web 组件时如何加载 repo?
- angular - LoadChildren 导航到特定路线 Angular 6
- python - Django 意外的 405 响应
- codeigniter - 如何获取数据库codeigniter一列中的所有数据?
- c# - 子域作为查询字符串
- c# - 使用 MS Bot SDK 4 构建的 Bot 在闲置一小时或更长时间后仍可用于 Facebook 频道
- javascript - HTML 包含带有 jsx、es2017 标签和其他标签的脚本
- react-native - React Native 样式不适用于父视图?
- python - 带有 Tuple() 或 List[] Python 3 的 While 循环中的比较运算符
- java - 插页式广告关闭后如何执行操作?