79680186

Date: 2025-06-26 08:59:41
Score: 1
Natty:
Report link

Appearently answer was pretty simple. Aside from HTTP solutions, there was an update to how clickonce operates at some point.

Sincere thanks to this pull request: https://github.com/dotnet/deployment-tools/pull/208

This basically solves all our problems, although the risky part that if you launch your application without ClickOnce tool (through vscode or whatever), these strings will be returned null. So testing was impossible, but these values are returned on live applications.

string updatedVersionStr = Environment.GetEnvironmentVariable("ClickOnce_UpdatedVersion");
string currentVersionStr = Environment.GetEnvironmentVariable("ClickOnce_CurrentVersion");

if (!string.IsNullOrEmpty(updatedVersionStr) && !string.IsNullOrEmpty(currentVersionStr))
{
    Version updatedVersion;
    Version currentVersion;

    if (Version.TryParse(updatedVersionStr, out updatedVersion) &&
        Version.TryParse(currentVersionStr, out currentVersion))
    {
        if (updatedVersion > currentVersion)
        {
            _logger.AddLog($"New version available. Current:{currentVersion}, New:{updatedVersion}");
            Application.Restart();
        }
    }
    else
    {
        //Error checking, other stuff, catches, whatever.
    }
}

Thank you all.

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (0.5): thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Hakkology