Metamation Developer Notes

  • Developer Notes
  • Resource Map
  • Tools
    • Code Formatting
    • Configuring Git
    • Assignments
    • Testing with Windows Sandbox
    • Single Binary Applications
    • Self-Updating Applications
  • Flux Workflow
    • Flux Workflow
    • Flux Development Style Guide
    • Release notes for Flux
    • SonarCloud analysis for Flux
    • Build a Flux SDK Program
    • Shipping Flux
    • Flux.Test
      • BasicBendAuto Test
      • LaserAuto.cs Detailed Documentation
      • Laserexample:Test1
  • Technical Notes
    • File formats
      • .FX File Format
      • Au(Gold) streams
      • .GEO File Format
      • .LST File Format
      • .LST file - technology
      • .BNC File Format
      • .WAD Files: Flux Resource Packages
      • .Curl Files: ASCII config information
    • Folders App
      • Data\Bendtools
      • Data\Machines
    • FluxCode
      • Welcome & Repo Map
      • Architecture & System Context
      • Subsystem *Bend* (Press Brake)
      • Subsystem *BCell* (Bend Cell Automation)
      • API Maps
      • Data Model Catalog
      • Design Patterns -- A Reader's Guide
      • Tests and Golden Paths
      • Guided Code Tours
      • CAM Glossary with Code Mapping
      • Assignments
      • Flux Onboarding Handbook
    • Data flow
      • Part
        • Part.Dwg
        • Part.Load
        • Part.Load to Part.Dwg
      • BendTech.cs
      • Bend Technology
      • Laser Cutting Technology
    • LTS (Long term support mechanism)
    • Machine ID Scheme
  • FluxTester
    • Commands and Scripts
    • Command Cookbook
    • Script Commands
    • BendTooling.cs Test Inventory
    • LaserTooling.cs Test Steps
    • Fluxtester Recipe Book
    • Nesting.cs Overview
    • Nesting.cs Recipe Book
    • Job.cs Overview
    • Job.cs Recipe Book
  • Software license
  • 3d party software
    • Python
  • Documentation
    • Bento documentation
      • Structure of a Bento page
      • Attributes
    • Software
      • Software Requirement
      • Installation
      • Git workflow for documentation contributors
    • Quick start guide
    • Workflow
      • Roles and responsibilities
      • Analyze
      • Edit
      • Proofread
      • Pre-Publish
      • Publish
      • Release cycle
      • Information required for Documentation Team
      • Checklist for Documenters
    • Styleguide
    • Flavoring
    • Translation
      • Ordering translation for a new document
    • Citations
    • Annotation
Tools
/
Self-Updating Applications

Self-Updating Applications

Introduction

Usually an application goes through multiple refinements and functionally updates during its life cycle. It is useful to have the applications self-update when a new version is released. This article discusses one such technique to enable self-update in a single-file console application.

Self-update demo

Click this to download the source skeleton implementing the self-update functionality. The zip file contains the TestApp console project. Unzip and launch the project in VisualStudio, switch it to release mode, compile and run. It checks for the new update and updates itself to a newer build. The update process looks something like this:

selfupdate demo1

From the next run onwards, it should continue as usual after the update check. The updates are checked at an interval of 60 minutes to avoid unnecessary launch delays.

selfupdate demo2

The update mechanism

Central to the update mechanism is a publish registry where information like the published build number and the download link are stored. When launched, the application reads the build number from the registry and compares it with its own build number. It downloads the application Exe from the download link to a temporary folder if a new newer build is found. The download is a self-contained, single Exe file. It then launches the downloaded application in update mode and terminates itself to free up the write lock on the current exe file. The target exe path, and parent process etc. are passed as command parameters to the updater app (it is the same exe running in a special mode). The updater copies itself to the given path and terminates to complete the update process.

Publishing a new build

Prerequisites

Following one-time preparation is needed before the first publish.

  • Obtain a publish registry credential from here.

  • Creating a OneDrive download URL[1]

TestApp.exe -publish

A TestApp developer publishes a new build after a significant functionality update/bug fix. Like the self-update, TestApp can also publish itself when launched with -publish command argument.

selfupdate publish

It expects following additional, positional parameters and needs a publish registry credential to complete the publish.

CSProjPath: The first publish parameter, defines path of the TestApp project file (.csproj). TestApp uses it to compile a self-contained, single Exe file. The publish settings are configured via a publish-profile, stored in the same csproj file.

PublishDir: The Exe is then copied to a local folder provided as the second publish parameter. This a local OneDrive[1] folder mapped to the download location. Note: Make sure the OneDrive Sync service is running in the background otherwise the download location mentioned next, will point to an incorrect TestApp version. Alternately, you can also publish it to any other local folder and upload the published Exe manually via web interface.

DownloadUrl: The third and the final parameter is the download URL from where the Exe can be streamed. This can be a read-only, public share created from the OneDrive[1] folder mentioned above. (See Creating a OneDrive download URL section below.)

Running TestApp.exe -publish with these parameters from the TestApp build directory (TestApp\Bin) prompts for publish registry Sign-in after the confirmation.

selfupdate publishprompt

Use the existing publish credential or create a new on using this Register link. Application is published on successful sign-in.
Note: The user-name is the registration email address.

selfupdate msg

Or an error message is displayed and sign-in is prompted again. Press Ctl+C to cancel the publish.

selfupdate error

The publish details and sign-in credentials are stored securely and are used in the subsequent publishes. So next publish command would just be TestApp.exe -publish from the TestApp\Bin.

Plugging the update mechanism

The update mechanism is reasonably modular and can be easily plugged into relatively smaller console tools. To plug:

  1. Copy the AutoUpdate.cs and the Res folder to the project’s root directory.

  2. Change file Res\K.dat build action to Embedded resource.

  3. Update the App.Name constant and the project namespace.

  4. Place AutoUpdate.Run () call near the application entry point.

  5. Add a single-file publish profile called FolderProfile to the project.

Creating a OneDrive download URL

The steps mentioned here assumes a local OneDrive setup. It should be easy to adapt them to browser based online interface.

  1. Create a local OneDrive folder on your computer and copy TestApp.exe to this folder (it can be same exe compiled to TestApp\Bin folder on a developer computer).

  2. Now right-click TestApp.exe and select OneDrive > Copy Link menu to create a public link.

    selfupdate 1drive1
  3. It should launch the Share dialog. We first need to change the link access from edit to view. To change:

    1. Click Anyone with the link can edit link.

    2. Now in the second dialog select Anyone radio if not already selected.

    3. Change Can edit to Can view and press the Apply button. This would bring back to the first dialog. Use the Copy button to copy the share link.

    selfupdate 1drive2
  4. The copied link would be in the format https://indiametamationsoft-my.sharepoint.com/:u:/g/personal/rajesh_metamation_com/EXKAkf99ld1KlJz_XAfs6hsBj0U0raViIZnZjUVVD-Y_dA?e=uXN86k. This is a browser link and cannot be used as direct download link. Remove the suffix after ? highlighted in the bold and append ?download=1 to change it to a direct download link. So the above link would change to: https://indiametamationsoft-my.sharepoint.com/:u:/g/personal/rajesh_metamation_com/EXKAkf99ld1KlJz_XAfs6hsBj0U0raViIZnZjUVVD-Y_dA?download=1
    Copying this to a browser would immediately start the download as shown in the image below.

    selfupdate download link

    Use this link as the DownloadUrl publish parameter.
    Note: Do not delete the TestApp.exe file (it changes the URL), it would get revised by a new one during the TestApp publish.


1. Any other file share service (Dropbox, Azure Files, Google Drive etc.) can be used instead of the OneDrive. There should be a local mapped folder where the published Exe can be stored. And, it should be possible to create a public download link to the Exe. The link needs to be public (no password protection), read-only and direct. A simple check can be performed by browsing the link in a browser in private-mode. Depending on the browser, it should start downloading it or prompt with the file-save dialog.

Contents

  • Introduction
  • Self-update demo
  • The update mechanism
  • Publishing a new build
  • Plugging the update mechanism
  • Creating a OneDrive download URL
Single Binary Applications Flux Workflow

      Copyright © 2025 TRUMPF Metamation. All rights reserved.

    Compiled by Bento