应用程序没有更新c# [英] Application is not updating c#

查看:59
本文介绍了应用程序没有更新c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。

我在C#中有一个简单的应用程序,用于跟踪一些汽车。

我试图让应用程序更新,当我点击特定按钮。



问题是,虽然我的应用程序版本是1.5.0.0,而要更新的版本(用xml编写)是1.7.0,我收到消息应用程序是最新的。



使用保管箱,我上传了我的应用程序的新版本和xml文件,代码如下:

Hello.
I have a simple application in C#, used for tracking some cars.
I am trying to make the application update, when I click the specific button.

The issue is that, although my application version is 1.5.0.0, and the version to update (wrote in xml) is 1.7.0, I receive the message "App is up to date".

Using the dropbox, I have uploaded the new version of my app and the xml file, which code looks like:

<?xml version="1.0 encoding = "utf-8"?>
<myapp>
    <version>1.7.0</version>
    <url>https://www.dropbox.com/s/vcf41vh1nim/myapp-new-1.7.0.exe</url>
</myapp>





单击按钮事件的代码如下:



The code for my button event click is the following:

private void btnUpdate_Click(object sender, EventArgs e)
        {
            string downloadUrl = "";
            Version newVersion = null;
            string xmlUrl = "https://www.dropbox.com/s/ezaes4wehs/update.xml";
            XmlTextReader xmlRead = null;
            try
            {
                xmlRead = new XmlTextReader(xmlUrl);
                xmlRead.MoveToContent();
                string elementName = "";
                if ((xmlRead.NodeType == XmlNodeType.Element) && (xmlRead.Name == "myapp"))
                {
                    while (xmlRead.Read())
                    {
                        if (xmlRead.NodeType == XmlNodeType.Element)
                        {
                            elementName = xmlRead.Name;
                        }
                        else
                        {
                            if ((xmlRead.NodeType == XmlNodeType.Text) && (xmlRead.HasValue))
                            {
                                switch (elementName)
                                {
                                    case "version":
                                        newVersion = new Version(xmlRead.Value);
                                        break;
                                    case "url":
                                        downloadUrl = xmlRead.Value;
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception msg)
            {
                MessageBox.Show(msg.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                if (xmlRead != null)
                    xmlRead.Close();
            }
            Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            if (applicationVersion.CompareTo(newVersion) < 0)
            {
                if (MessageBox.Show("A new version is available to download!Continue?", "Update My App", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)                
                {
                    System.Diagnostics.Process.Start(downloadUrl);
                }
            }
            else
            {
                MessageBox.Show("Application is up to date!", "My App", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }





我没有收到任何错误。我尝试过组合来改变版本,但仍然是相同的。

有人可以帮忙或分享建议吗?



提前谢谢。



I don`t receive any errors. I tried combinations to change versions, but still the same.
Can someone help on this or share an advice?

Thank you in advance.

推荐答案

我测试了你的代码。为了做到这一点,我改变了这个:

I tested your code. In order to do so, I changed just this:
private void btnUpdate_Click(object sender, EventArgs e)
{
    string xml =
@"<?xml version=""1.0"" encoding = ""utf-8""?>
<myapp>
    <version>1.7.0</version>
    <url>https://www.dropbox.com/s/vcf41vh1nim/myapp-new-1.7.0.exe</url>
</myapp>";

    // same stuff

        xmlRead = new XmlTextReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(xml))));

    // same stuff
}



在AssemblyInfo.cs中我设置了这个:


And in the AssemblyInfo.cs I set this:

[assembly: AssemblyVersion("1.5.0.0")]



它的确有效。你是否在调试器中运行它并检查了每一行上发生了什么?


And it works. Did you run it in the debugger and inspected what's happening on each line?


这篇关于应用程序没有更新c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆