1

We have a tiny WPF-software that mostly operates in the taskbar with .NET 9.0. Just open and forget kind, with very little user input. ClickOnce was chosen as our distribution platform.

Updates can be forced by choosing this version to be the minimum required version before the application starts. However, we want the application to check for updates while the application is running as well. A hotfix or a quick update may require client's application to be updated swiftly. For this, ClickOnce has a radio option that says "after the application starts".

However, this radio option for "After the Application starts" is not available. A deeper research shows that the ClickOnce for apps above .NET 9.0 no longer allows managing updates after the application starts. There is no way to give update intervals as well. I was thinking perhaps another setting interferes with it, but no.

Has anyone solved this problem with ClickOnce ? Is there a solution ? For research: https://learn.microsoft.com/en-us/visualstudio/deployment/clickonce-deployment-dotnet?view=vs-2022

Thanks.

asked Jun 26, 2025 at 8:00
2
  • 1
    A solution is pretty simple, have your application periodically query your server(s) about the newest version, check if the current running version is out of date, and if so restart itself (maybe with a dialog so the user knows what's happening). This way you still don't have to manage the entire updating itself, just a simple version check. Commented Jun 26, 2025 at 8:35
  • @MindSwipe many thanks for your kind input, we found another solution, please check the answer i provided. Commented Jun 26, 2025 at 9:00

1 Answer 1

2

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}");
 System.Windows.Forms.Application.Restart();
 System.Windows.Application.Current.Shutdown();
 }
 }
 else
 {
 //Error checking, other stuff, catches, whatever.
 }
}

Thank you all.

Edit: Important edit for application restart

Edit-2: This is also not the desired behaviour for my case, updatedversion is not updated when you release new updates on ClickOnce if the application is not restarted.

However there is a way to get required info from your app manifest. If you are distributing the application through a http link, following code basically searches the app manifest and finds the attribute "MinimumRequiredVersion". Each update needs to go parallel with the MinimumRequiredVersion, otherwise the application will require user input, which is not the ideal case for an "open and forget" kind of application.

Following code is just an edit for further info, if anyone needs.

var xmlString = await _httpClient.GetStringAsync(manifestUrl);
var doc = XDocument.Parse(xmlString);
var deploymentElement = doc.Descendants()
 .FirstOrDefault(x => x.Name.LocalName == "deployment");
var minReqVersion = deploymentElement?.Attribute("minimumRequiredVersion")?.Value;
if (Version.TryParse(minReqVersion, out var version))
 return version;
return null;
answered Jun 26, 2025 at 8:54
Sign up to request clarification or add additional context in comments.

1 Comment

Setting of environment vars is not rocket science, so testing should be easy

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.