A library to update .NET applications

Here is a short example of using the AutoUpdater .NET library: https://github.com/ravibpatel/AutoUpdater.NET which is popular for auto updating .NET applications. One example of a popular application that uses it is CyberDuck, which is a tool to manage files on various services such as s3, dropbox, ftp e.t.c

The first step is to create an update file that points to the executable and stores the current version number:


<?xml version="1.0" encoding="UTF-8"?>
<item>
  <version>1.0.0</version>
  <url>https://mypath.s3.amazonaws.com/myapp_1.0.0.exe</url>
  <changelog>https://s3.amazonaws.com/mypath/changelog.html</changelog>
  <mandatory>false</mandatory>
</item>

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;

AutoUpdater.InstalledVersion = new Version(version);
AutoUpdater.CheckForUpdateEvent += (UpdateInfoEventArgs args) =>
{
	if (args.IsUpdateAvailable)
    {
    	MessageBoxWarning msg = new()
        	{
            	Text = "There is an update to the software, would you like to install it?"
            };

			msg.Topmost = true;
            
            if (msg.ShowDialog() == false)
            {
                return;
            }

            try
            {
            	if (AutoUpdater.DownloadUpdate(args))
               	{
                    	Close();
                       	Environment.Exit(0);
                }
            }
            catch (Exception exception)
            {
                	MessageBox.Show(exception.Message, exception.GetType().ToString(),
                            MessageBoxButton.OK, MessageBoxImage.Error);
            }

	}
};
AutoUpdater.Start("https://s3.amazonaws.com/mypath/update.xml");
AutoUpdater.AppTitle = "My App";
AutoUpdater.Proxy = WebRequest.DefaultWebProxy;

Post a Comment

Previous Post Next Post