AutoUpdater.NET 是一套类库,允许 .NET 开发人员轻松地将自动更新功能添加到他们的经典桌面应用程序项目中。
AutoUpdater.NET 是一套类库,允许 .NET 开发人员轻松地将自动更新功能添加到他们的经典桌面应用程序项目中。
AutoUpdater.NET is a class library that allows .NET developers to easily add auto-update functionality to their classic desktop application projects.
PM> Install-Package Autoupdater.NET.Official
This library only works for WinForms or WPF application projects.
AutoUpdater.NET downloads the XML file containing update information from your server. It uses this XML file to get the information about the latest version of the software. If the latest version of the software is greater than the current version of the software installed on the User's PC, then AutoUpdater.NET shows an update dialog to the user. If they press the update button to update the software, then It downloads the update file (Installer) from URL provided in the XML file and executes the installer file it just downloaded. It is the job of the installer after this point to carry out the update. If you provide zip file URL instead of installer, then AutoUpdater.NET will extract the contents of the zip file to the application directory.
AutoUpdater.NET uses an XML file located on a server to get the release information about the latest version of the software. You need to create an XML file like below, and then you need to upload it to your server.
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>2.0.0.0</version>
<url>https://rbsoft.org/downloads/AutoUpdaterTest.zip</url>
<changelog>https://github.com/ravibpatel/AutoUpdater.NET/releases</changelog>
<mandatory>false</mandatory>
</item>
There are two things you need to provide in an XML file, as you can see above.
version (Required): You need to provide the latest version of the application between version tags. Version should be in X.X.X.X format.
url (Required): You need to provide the URL of the latest version installer file or zip file between url tags. AutoUpdater.NET downloads the file provided here and installs it when the user presses the Update button.
changelog (Optional): You need to provide the URL to the change log of your application between changelog tags. If you don't provide the URL of the changelog, then the update dialog won't show the change log.
mandatory (Optional): You can set this to true if you don't want the user to skip this version. This will ignore Remind Later and Skip options and hide both Skip and Remind Later buttons on the update dialog.
<mandatory mode="2">true</mandatory>
<mandatory minVersion="1.2.0.0">true</mandatory>
executable (Optional): You can provide the path of the executable if it was changed in the update. It should be relative to the installation directory of the application. For example, if the new executable is located inside the bin folder of the installation directory, then you should provide it as shown below.
<executable>bin\AutoUpdaterTest.exe</executable>
<checksum algorithm="MD5">Update file Checksum</checksum>
You can also use the XML creator tool created by one of the users to create the XML file. You can download it from here.
After you are done creating and uploading the XML file, It is straightforward to add an auto-update functionality to your application.
First, you need to add the following line at the top of your form.
using AutoUpdaterDotNET;
Now you need to add the following line to your main form constructor or in Form_Load event. You can add this line anywhere you like. If you don't like to check for update when the application starts, then you can create a Check for update button and add this line to the Button_Click event.
AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
Start method of AutoUpdater class takes the URL of the XML file you uploaded to the server as a parameter.
AutoUpdater.Start should be called from the UI thread.
AutoUpdater.NET uses Assembly version to determine the current version of the application. You can update it by going to Properties of the project as shown in the following screenshot.
The version specified in the XML file should be higher than the Assembly version to trigger the update.
If you want to provide your own Assembly, then you can do it by providing the second argument of the Start method as shown below.
AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml", myAssembly);
If you don't want AutoUpdater.NET to determine the installed version from assembly, then you can provide your own version by assigning it to the InstalledVersion field as shown below.
AutoUpdater.InstalledVersion = new Version("1.2");
If you like to use ftp XML URL to check for updates or download the update file, then you can provide your FTP credentials in the alternative Start method as shown below.
AutoUpdater.Start("ftp://rbsoft.org/updates/AutoUpdaterTest.xml", new NetworkCredential("FtpUserName", "FtpPassword"));
If you are using FTP download URL in the XML file, then credentials provided here will be used to authenticate the request.
If you want to check for updates synchronously, then set Synchronous to true before starting the update as shown below.
AutoUpdater.Synchronous = true;
If you don't want to show the Skip button on the Update form, then just add the following line with the above code.
AutoUpdater.ShowSkipButton = false;
If you don't want to show the Remind Later button on the Update form, then just add the following line with the above code.
AutoUpdater.ShowRemindLaterButton = false;
If you want to ignore previously set Remind Later and Skip settings, then you can set Mandatory property to true. It will also hide the Skip and Remind Later button. If you set Mandatory to true in code, then the value of Mandatory in your XML file will be ignored.
AutoUpdater.Mandatory = true;
You can enable forced updates by setting Mandatory property to true and setting UpdateMode to value of Mode.Forced or
Mode.ForcedDownload. Mode.Forced option will hide Remind Later, Skip, and Close buttons on the standard update
dialog. Mode.ForcedDownload option will skip the standard update dialog and start downloading and updating the
application without user interaction. Mode.ForceDownload option will also ignore the value of the OpenDownloadPage
flag.
AutoUpdater.Mandatory = true;
AutoUpdater.UpdateMode = Mode.Forced;
You can provide Basic Authentication for XML, Update a file, and Change Log as shown in the below code.
BasicAuthentication basicAuthentication = new BasicAuthentication("myUserName", "myPassword");
AutoUpdater.BasicAuthXML = AutoUpdater.BasicAuthDownload = AutoUpdater.BasicAuthChangeLog = basicAuthentication;
Set the User-Agent string to be used for HTTP web requests so you can differentiate them in your web server request logs.
AutoUpdater.HttpUserAgent = "AutoUpdater";
You can turn on error reporting by adding the below code. If you do this, AutoUpdater.NET will show an error message if there is no update available or if it can't get to the XML file from the web server.
AutoUpdater.ReportErrors = true;
If your application doesn't need administrator privileges to replace the old version, then you can set RunUpdateAsAdmin to false.
AutoUpdater.RunUpdateAsAdmin = false;
If you don't want to download the latest version of the application and just want to open the URL between url tags of your XML file, then you need to add the following line with the above code.
AutoUpdater.OpenDownloadPage = true;
This kind of scenario is useful if you want to show some information to users before they download the latest version of the application.
If you don't want users to select Remind Later time when they press the Remind Later button of the update dialog, then you need to add the following lines with the above code.
AutoUpdater.LetUserSelectRemindLater = false;
AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Days;
AutoUpdater.RemindLaterAt = 2;
In the above example, when a user presses the Remind Later button of the update dialog, It will remind the user for update after 2 days.
If your XML and Update file can only be used from a certain Proxy Server, then you can use the following settings to tell AutoUpdater.NET to use that proxy. Currently, if your Changelog URL is also restricted to Proxy server, then you should omit the changelog tag from the XML file cause it is not supported using Proxy Server.
var proxy = new WebProxy("ProxyIP:ProxyPort", true)
{
Credentials = new NetworkCredential("ProxyUserName", "ProxyPassword")
};
AutoUpdater.Proxy = proxy;
You can specify where you want to download the update file by assigning the DownloadPath field as shown below. It will be used for ZipExtractor too.
AutoUpdater.DownloadPath = Application.StartupPath;
If you are using a zip file as an update file, then you can set the "InstallationPath" equal to the path where your app is installed. This is only necessary when your installation directory differs from your executable path. Make s
暂无开放 Issues,或尚未同步最近议题。