AutoUpdater.NET

repository·master·Indexed 26 days ago

https://github.com/ravibpatel/autoupdater.net

A class library for .NET desktop developers (WinForms/WPF) to implement seamless auto-update functionality via an XML configuration file hosted on a remote server. It supports .NET Framework 4.6.2+, .NET Core 3.1, and .NET 5.0+, providing features such as mandatory updates, custom update dialogs, checksum verification, and support for various authentication methods including FTP and Basic Auth.

Tokens
4.2K
Snippets
15
Records
18
Agent score
36%

What's inside AutoUpdater.NET

  1. Supported Runtimes and Platforms

    master

    AutoUpdater.NET is designed for classic desktop application projects (WinForms or WPF) and supports the following environments:

    Supported .NET Versions:

    • .NET Framework 4.6.2 or above
    • .NET Core 3.1
    • .NET 5.0 or above

    Supported Windows Versions:

    • Windows 8 or above
    • Windows versions lower than 8: Requires .NET Framework 4.5 or above installed for ZipExtractor to function. To avoid this requirement, use an installer file instead of a zip file for updates.
  2. Configure Persistence Provider

    master

    By default, AutoUpdater.NET saves 'Remind Later' and 'Skip' settings in the Windows Registry. You can change this by assigning a new PersistenceProvider. For .NET 4.0+, you can use JsonFilePersistenceProvider to save settings to a JSON file.

    string jsonPath = Path.Combine(Environment.CurrentDirectory, "settings.json");
    AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);
  3. Configure Update Dialog UI and Buttons

    master

    Customize the appearance and interaction of the update form:

    • Hide Buttons: Use AutoUpdater.ShowSkipButton = false or AutoUpdater.ShowRemindLaterButton = false to remove specific buttons.
    • Form Size: Set AutoUpdater.UpdateFormSize using a System.Drawing.Size object.
    • Icon: Set AutoUpdater.Icon to a project resource (recommended size 64x64).
    • TopMost: Set AutoUpdater.TopMost = true to keep dialogs on top of other windows.
    • Owner Window: Use AutoUpdater.SetOwner(window) to ensure dialogs are correctly focused relative to your main Form or WPF Window.
    AutoUpdater.ShowSkipButton = false;
    AutoUpdater.ShowRemindLaterButton = false;
    AutoUpdater.UpdateFormSize = new System.Drawing.Size(800, 600);
    AutoUpdater.Icon = Resources.Icon;
    AutoUpdater.TopMost = true;
    AutoUpdater.SetOwner(yourMainFormOrWpfWindow);
  4. Configure Authentication and Network Settings

    master

    Handle secure connections and network requirements:

    • FTP: Use the alternative Start method to provide NetworkCredential for FTP XML URLs and downloads.
    • Basic Auth: Use BasicAuthentication objects to set credentials for BasicAuthXML, BasicAuthDownload, and BasicAuthChangeLog.
    • User-Agent: Set AutoUpdater.HttpUserAgent to identify your requests in server logs.
    • Proxy: Configure AutoUpdater.Proxy using a WebProxy object. Note: Changelog URLs are not supported when using a Proxy.
    // FTP usage
    AutoUpdater.Start("ftp://rbsoft.org/updates/AutoUpdaterTest.xml", new NetworkCredential("FtpUserName", "FtpPassword"));
    
    // Basic Authentication
    BasicAuthentication basicAuthentication = new BasicAuthentication("myUserName", "myPassword");
    AutoUpdater.BasicAuthXML = AutoUpdater.BasicAuthDownload = AutoUpdater.BasicAuthChangeLog = basicAuthentication;
    
    // Proxy Server
    var proxy = new WebProxy("ProxyIP:ProxyPort", true)
    {
        Credentials = new NetworkCredential("ProxyUserName", "ProxyPassword")
    };
    AutoUpdater.Proxy = proxy;
  5. Configure File Paths and Extraction

    master

    Manage where update files are stored and how they are extracted:

    • Download Path: Set AutoUpdater.DownloadPath to specify the download location.
    • Installation Path: Set AutoUpdater.InstallationPath if your installation directory differs from your executable path (required for Zip updates).
    • Executable Path: Set AutoUpdater.ExecutablePath to specify a relative path to the executable to run after the update (overrides XML 'executable' value).
    • Clear Directory: Set AutoUpdater.ClearAppDirectory = true to wipe the application directory before extracting the update.
    AutoUpdater.DownloadPath = Application.StartupPath;
    AutoUpdater.InstallationPath = Application.StartupPath;
    AutoUpdater.ExecutablePath = "bin\\AutoUpdater.exe";
    AutoUpdater.ClearAppDirectory = true;
  6. Configure AutoUpdater.NET Installation and Update Behavior

    master

    You can customize how AutoUpdater.NET behaves by setting various configuration properties before calling AutoUpdater.Start().

    Key behaviors include:

    • Manual Versioning: If you don't want to use the assembly version, set AutoUpdater.InstalledVersion.
    • Synchronous Checks: Set AutoUpdater.Synchronous = true to check for updates synchronously.
    • Privileges: Set AutoUpdater.RunUpdateAsAdmin = false if your application does not require administrator rights to replace files.
    • Error Reporting: Enable AutoUpdater.ReportErrors = true to show error messages if no update is found or the XML is unreachable.
    • Download Page: Set AutoUpdater.OpenDownloadPage = true to open the URL specified in your XML instead of downloading the file automatically.
  7. Configure Forced and Mandatory Updates

    master

    To force users to update, set AutoUpdater.Mandatory = true. You can further control the update mode using AutoUpdater.UpdateMode:

    • Mode.Forced: Hides 'Remind Later', 'Skip', and 'Close' buttons on the standard dialog.
    • Mode.ForcedDownload: Skips the standard dialog entirely and starts downloading/updating without user interaction. This also ignores the OpenDownloadPage flag.
    AutoUpdater.Mandatory = true;
    AutoUpdater.UpdateMode = Mode.Forced;
  8. Configure Remind Later Settings

    master

    Control how the 'Remind Later' button behaves. You can disable the user's ability to choose a custom time and instead force a specific interval.

    // Users will be reminded after 2 days automatically
    AutoUpdater.LetUserSelectRemindLater = false;
    AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Days;
    AutoUpdater.RemindLaterAt = 2;
  9. Build AutoUpdater.NET for local development

    master

    To build the project for development purposes, follow these steps:

    1. Disable Signing: Disable code signing in the project properties for both AutoUpdater.NET and ZipExtractor.
    2. Modify Target Frameworks: Edit the .csproj files for both projects. Change the <TargetFrameworks> (plural) tag to a single <TargetFramework> (singular) tag using your preferred version.
      • Example: Change <TargetFrameworks>net462;netcoreapp3.1;net5.0-windows</TargetFrameworks> to <TargetFramework>net5.0-windows</TargetFramework>.
    3. Build ZipExtractor: Build the ZipExtractor project in Release configuration.
    4. Handle .NET Core/5+ Publishing: For .NET Core 3.1 or above, use the dotnet publish command instead of build.
    5. Copy Resources: Copy the resulting executable from the publish output to the AutoUpdater.NET/Resources folder.
    6. Note on .NET Framework 4.5: If using Visual Studio 2022, you may need to follow specific steps to enable building for .NET Framework 4.5 as it is not enabled by default.
  10. Check for Updates Frequently using Timers

    master

    To check for updates at regular intervals, wrap the AutoUpdater.Start method in a timer.

    // WinForms Example
    System.Timers.Timer timer = new System.Timers.Timer
    {
        Interval = 2 * 60 * 1000,
        SynchronizingObject = this
    };
    timer.Elapsed += delegate
    {
        AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
    };
    timer.Start();
    
    // WPF Example
    DispatcherTimer timer = new DispatcherTimer {Interval = TimeSpan.FromMinutes(2)};
    timer.Tick += delegate
    {
        AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTestWPF.xml");
    };
    timer.Start();
  11. Handle Application Exit Logic Manually

    master

    Subscribe to the ApplicationExitEvent to perform custom logic (like showing a 'Closing...' message) before the application fully exits during an update process.

    AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;
    
    private void AutoUpdater_ApplicationExitEvent()
    {
        Text = @"Closing application...";
        Thread.Sleep(5000);
        Application.Exit();
    }