我开发了wpf应用程序并创建了安装文件。 它工作正常,但如何检查以及如何安装最新版本的编程方式,当点击按钮如何在wpf应用程序中检查更新安装新版本
0
A
回答
0
首先,确保您的应用程序启用检查更新。右键点击你的项目 - >属性 - >发布标签 - >更新。勾选复选框“应用程序应检查更新”
使用下面的代码,在按钮单击事件来检查使用ClickOnce更新
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;
}
}
}
}
0
查找到部署(https://msdn.microsoft.com/en-us/library/t71a733d(v=vs.140).aspx )。每次程序启动时都会检查更新。
在Visual Studio 2015年,正好击筑 - >发布,然后按照向导。我发现它非常简单。
相关问题
- 1. 代码检查更新,安装新版本的应用程序
- 2. 安卓更新/安装版本检查
- 3. 退出后台WPF应用程序来安装更新版本
- 4. 安装我在C#中创建的WPF应用程序的更新版本
- 5. 检查应用程序是否已更新或新安装
- 6. Android:您可以检查应用程序安装是否新鲜或已安装应用程序的旧版本?
- 7. 程序版本检查和更新
- 8. 如何将buildroot安装程序更新到更高版本?
- 9. 如何在较新版本上安装旧版本的UWP应用程序?
- 10. 如何在安装新版本时删除以前版本的应用程序
- 11. 如何检查应用程序更新
- 12. Inno安装程序在安装前检查更新
- 13. 如何让msi安装程序在较新的版本上安装旧版本?
- 14. 如何如何创建,无需重新安装在新版本的应用程序更新应用程序的更新补丁为Windows创建应用
- 15. 如何使用NSUserDefaults检查应用程序的最新版本
- 16. 如何在android中安装新版本
- 17. 在安装有意图的Android中安装较新版本的应用程序
- 18. 检查Windows安装程序版本
- 19. 如何在运行时检查Django中安装的应用程序的版本?
- 20. 使用MSI安装的WPF应用程序的ClickOnce更新
- 21. 更新本机库,无需重新安装应用程序
- 22. 如何在应用程序更新后找出以前安装的应用程序版本的versionCode?
- 23. 如何检查iOS中用户最初安装的应用程序版本
- 24. BizTalk应用程序未能安装:“已安装的应用程序的更新版本”
- 25. 如何检查应用程序的版本并请求用户更新?
- 26. 如何在Chrome应用程序中动态更新版本号?
- 27. 如果新版本可用,如何在Android应用程序中强制更新?
- 28. 如何在安装应用程序之前检查JRE版本,Mac安装程序
- 29. 检查更新的版本
- 30. 应用程序版本更新sniplets