未涉及过winform升级,研究一阵,大致出来个不成熟的方案。

我的解决方案(判断升级,升级程序下载安装包的压缩包,解压,自动安装,重新启动程序)。

1、首先根据服务器中软件版本号和本地软件版本号是否一致,来确认程序是否需要升级。

  1)本地可以用现成AssemblyInfo.cs文件中assembly: AssemblyVersion("1.0.0.0")来记录,通过反射来获取版本号:System.Reflection.Assembly.GetExecutingAssembly().GetName().Version。

  2)需要升级启动升级程序Update.exe,并关闭主程序。

  Process p = new Process();
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardOutput = true;
  p.StartInfo.FileName = fileName;
  p.StartInfo.CreateNoWindow = true;
  p.StartInfo.Arguments = versionInfo.Url;//判断是否需要升级时返回VersionInfo类型,包括新版本号和下载链接,传值给升级程序
  p.Start();
  System.Environment.Exit(System.Environment.ExitCode);

2、升级程序。

  执行下载及解压,覆盖安装。

  缺点:代码有待优化;

     完全安装,耗时;

     对网络有要求;、

     本地数据库不能保留原有数据。

  //升级程序接收参数
  static class Program
  {
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FMUpdate(args));
}
  }   private string _url;
  public FMUpdate(string[] args)
  {
  InitializeComponent();
  _url = args[];
  }
  
  private void FMUpdate_Load(object sender, EventArgs e)
  {
  WebClient wc = new WebClient();
  wc.DownloadProgressChanged += wc_DownloadProgressChanged;
  wc.DownloadFileAsync(new Uri(_url), @"c:\update.rar");
  }
private void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
Action act = () =>
{
this.progressBar1.Value = e.ProgressPercentage;
this.lblTip.Text = "正在下载...";
//this.label1.Text = e.ProgressPercentage + "%"; };
this.Invoke(act); if (e.ProgressPercentage == )
{
//下载完成之后开始覆盖
this.lblTip.Text = "正在解压..."; try
{
var result = CompressHelper.Uncompress(@"c:\update.rar", “解压路径”);
if (result)
{
progressBar1.Value = ;
this.lblTip.Text = "准备安装..."; //备份之前数据库
var dbFile = Application.StartupPath + "/db/数据库文件.db";
if (File.Exists(dbFile))
{
var bakFile = Application.StartupPath + "/backup/" + DateTime.Now.ToString("yyyyMMddHHmmssms") + ".bak";
var bakDirectory = Path.GetDirectoryName(bakFile);
DirectoryInfo directoryInfo = new DirectoryInfo(bakDirectory);
if (!directoryInfo.Exists)
{
directoryInfo.Create();
}
else
{
//删除7天前的备份文件
var files = directoryInfo.GetFiles();
if (files != null && files.Length > )
{
foreach (var file in files)
{
if (file.CreationTime.AddDays() < DateTime.Now)
{
file.Delete();
}
}
}
}
//备份文件
File.Move(dbFile, bakFile);
}
this.lblTip.Text = "准备安装";
Install();
this.lblTip.Text = "安装完成";
var mainFile = Application.StartupPath + @"\Main.exe";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = mainFile;
p.StartInfo.CreateNoWindow = true;
p.Start();
this.Close();
}
else
{
MessageBox.Show("更新失败");
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("更新失败", ex.Message);
this.Close();
} }
    }     private void Install()
    {
try
{
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = $"/i {_temp}利万嘉收银系统安装文件.msi /qb-!";// /qb显示基本界面 /qb-!或者/qb!- 基本界面无取消按钮
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
p.Close();
}
catch (Exception ex)
{
MessageBox.Show("更新失败:" + ex.Message);
}
    }

再说下关于增量升级。

1、单独升级站点,保存项目的资源文件、程序集等。

2、xml记录版本及更新的文件。

3、启动升级程序,从升级站点直接拷贝修改的文件、程序集。

遗留问题:

1、增量升级跨多个版本,升级xml每个版本都记录?

2、两种方案对数据库操作,执行数据库脚本?如何执行?

求见解。。。。。。

Git上现成升级:https://github.com/iccfish/FSLib.App.SimpleUpdater

winform自动升级方案的更多相关文章

  1. c# winform 自动升级

    winform自动升级程序示例源码下载  客户端思路: 1.新建一个配置文件Update.ini,用来存放软件的客户端版本: [update] version=2011-09-09 15:26 2.新 ...

  2. 分享一个客户端程序(winform)自动升级程序,思路+说明+源码

    做winform的程序,不管用没用过自动更新,至少都想过自动更新是怎么实现的. 我这里共享一个自动更新的一套版本,给还没下手开始写的人一些帮助,也希望有大神来到,给指点优化意见. 本初我是通过sock ...

  3. winform 自动升级

    自动升级系统OAUS的设计与实现(续) (附最新源码) http://www.cnblogs.com/zhuweisky/p/4209058.html Winform在线更新 http://www.c ...

  4. C/S WinForm自动升级

    这二天刚好完成一个C/S 自动升级的功能 代码分享一下 /// <summary>    /// 版本检测    /// </summary>    public class ...

  5. 一种让运行在CentOS下的.NET CORE的Web项目简单方便易部署的自动更新方案

    一.项目运行环境 项目采用的是.NET5开发的Web系统,独立部署在省内异地多台CentOS服务器上,它们运行在甲方专网环境中(不接触互联网),甲方进行业务运作时(一段时间内)会要求异地服务器开机上线 ...

  6. 在WinForm中使用Web Service来实现软件自动升级

    来源:互联网 winform程序相对web程序而言,功能更强大编程更方便,但软件更新却相当麻烦,要到客户端一台一台地升级,面对这个实际问题,在最近的一个小项目中,本人设计了一个通过软件实现自动升级技术 ...

  7. 在WinForm中使用Web Services 来实现 软件自动升级( Auto Update ) (C#)

    winform程序相对web程序而言,功能更强大,编程更方便,但软件更新却相当麻烦,要到客户端一台一台地升级,面对这个实际问题,在最近的一个小项目中,本人设计了一个通过软件实现自动升级技术方案,弥补了 ...

  8. 在WinForm中使用Web Services 来实现 软件 自动升级( Auto Update ) (C#)

    winform程序相对web程序而言,功能更强大,编程更方便,但软件更新却相当麻烦,要到客户端一台一台地升级,面对这个实际问题,在最近的一个小项目中,本人设计了一个通过软件实现自动升级技术方案,弥补了 ...

  9. 黄聪:C#Winform程序如何发布并自动升级(图解)

    有不少朋友问到C#Winform程序怎么样配置升级,怎么样打包,怎么样发布的,在这里我解释一下打包和发布关于打包的大家可以看我的文章C# winform程序怎么打包成安装项目(图解)其实打包是打包,发 ...

随机推荐

  1. android 使用UDP发送数据 DatagramSocket 创建对象为null

    DatagramSocket socket=null; try { socket = new DatagramSocket();  //这里创建对象为空 } catch (SocketExceptio ...

  2. js之function

    function* function* 这种声明方式(function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个  Generator  对象. 你 ...

  3. 【Web】Nginx配置规则

    Nginx配置基本说明 以下是nginx的基本配置文件如下(编辑命令:vi /usr/local/nginx/conf/nginx.conf): #user nobody; #nginx进程数,建议设 ...

  4. java struts2 的 文件下载

    jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  5. 整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建

    整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建 1.   介绍 Commonservice-system是一个大型分布式.微服务.面向企业的JavaEE体系快速研发平台,基于模 ...

  6. (19)3 moons and a planet that could have alien life

    https://www.ted.com/talks/james_green_3_moons_and_a_planet_that_could_have_alien_life/transcript00:1 ...

  7. 6. Uniforms in American's Eyes 美国人眼里的制服

    6. Uniforms in American's Eyes 美国人眼里的制服 (1) Americans are proud of their variety and individuality,y ...

  8. 535 5.7.8 Error: authentication failed: generic failure安装EMOS时SMTP测试报错

    按照官方手册安装EMOS时候,进行到SMTP认证测试的时候报如下错: 535 5.7.8 Error: authentication failed: generic failure 原来是因为之前关闭 ...

  9. 反射List<M> To DataTable|反射IList To DataTable|反射 DataTable To List<M>

    将DataTable集合反射获取 List<M> /// <summary> /// 根据DataTable集合反射获取 List<M> /// </summ ...

  10. leetcode-[3]Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line 思 ...