WinForm 自动更新

时间 2018/2/26 10:27:55 加载中...

WinForm 自动更新


查阅了一些相关资料,最终根据此篇介绍来实现自动更新功能。

http://www.cnblogs.com/KnightsWarrior/archive/2010/10/20/1856255.html


效果图:


2018-02-26_10-58-31.gif


大概思路如下:

 

在服务器端配置版本号,如果客户端版本号低于最新的版本号,则在客户端启动的时候

提示是否更新。

 

对其提供的代码做了一些修改,将英文修改为了中文。

代码地址:

https://github.com/shenqiangbin/AutoUpdater


项目中使用方法:


在项目中引用 AutoUpdater.dll,并在项目中添加配置文件 Autoupdater.config。

在项目中添加如下代码:


private void CheckUpdate()
{
    #region check and download new version program
    bool bHasError = false;
    IAutoUpdater autoUpdater = new AutoUpdater();
    try
    {
        autoUpdater.Update();
    }
    catch (WebException exp)
    {
        MessageBox.Show("找不到指定的资源");
        bHasError = true;
    }
    catch (XmlException exp)
    {
        bHasError = true;
        MessageBox.Show("文件下载失败");
    }
    catch (NotSupportedException exp)
    {
        bHasError = true;
        MessageBox.Show("升级地址配置错误");
    }
    catch (ArgumentException exp)
    {
        bHasError = true;
        MessageBox.Show("文件下载失败");
    }
    catch (Exception ex)
    {
        bHasError = true;
        MessageBox.Show("更新失败");
    }
    finally
    {
        if (bHasError == true)
        {
            try
            {
                autoUpdater.RollBack();
            }
            catch (Exception ex)
            {
                //Log the message to your file or database
                MessageBox.Show(ex.Message);
            }
        }
    }
    #endregion
}


在 Autoupdater.config 文件中配置服务器端配置文件地址,比如:

http://www.sqber.com/app/AutoupdateService.xml

 

在服务端文件夹中放入  BuildXML.exe 和 应用程序 来生成服务器端的配置文件。

之后手动修改 needRestart="true",则会更新后重新启动程序。

 

注意:

发布新的程序时,要修改其程序集的版本号

 

查阅的相关资料:

 

http://blog.csdn.net/u011981242/article/details/51148667

http://blog.csdn.net/qq395537505/article/details/50751888

http://blog.csdn.net/wangjian0619/article/details/27680203

http://www.cnblogs.com/KnightsWarrior/p/ForumBlogCode.html

http://www.cnblogs.com/KnightsWarrior/archive/2010/10/20/1856255.html


扫码分享
版权说明
作者:SQBER
文章来源:http://blog.sqber.com/articles/WinForm-Auto-Update.html
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。