winform 自动更新

发布时间 2023-11-07 15:05:46作者: 越吃越瘦

原文地址:https://github.com/ravibpatel/AutoUpdater.NET

一:代码中设置

引入 using AutoUpdaterDotNET;

string updateIp =**.**.**.**;  //ip地址

string updatePort = ****;//端口号

using (TcpClient client = new TcpClient())
{
IAsyncResult tcpResult = client.BeginConnect(updateIp, updatePort, null, null);
if (!tcpResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3)))
{
DialogResult dr = MessageBox.Show(String.Format("自动更新端口无法访问{0}:{1},请联系运维人员!是否继续使用当前版本?", updateIp, updatePort), "前台显示!", MessageBoxButtons.OKCancel);

if (dr == DialogResult.Cancel)
{
Environment.Exit(0);
}
//MessageBox.Show(String.Format("自动更新端口无法访问{0}:{1},请联系运维人员!!,将继续使用当前程序", updateIp, updatePort))

}
}

//----------自动更新----------
Assembly asm = Assembly.GetExecutingAssembly();

AssemblyCopyrightAttribute asmcpr = (AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(asm, typeof(AssemblyCopyrightAttribute));
AssemblyCompanyAttribute asmcpn = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(asm, typeof(AssemblyCompanyAttribute));

string version = string.Format("{0} {1}", asmcpr.Copyright, asmcpn.Company);
AutoUpdater.UpdateMode = Mode.ForcedDownload;

 AutoUpdater.Start(String.Format("http://{0}:{1}/spdupdate.xml", updateIp, updatePort), asm);//开发库更新

ServicesDto.Version = asm.GetName().Version.ToString();

在程序中设置版本号:

 二、服务中设置

1、在nginx.conf 中配置自动更新地址:

server {
        listen 更新端口号 ;
        server_name _;


        location / {
            root /home/放自动更新文件的文件夹地址名称;
        }

        location /SPD3 {
            root /home/spdtest/SPD3_PDA/;
        }


        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

2、写一个xml文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?><item>
    <version>1.2.8.5</version>
    <url>http://ip:端口/Debug.zip</url>
    <mandatory mode="2">true</mandatory>
</item>

3、更新的包(必须为.zip)和xml都放在nginx配置好的文件夹目录下面

 4、访问:http://ip:端口/spdupdate.xml  可成功访问则配置成功