23

I updated my ClickOnce application and then when the user runs they are asked if they want to install the new version.

I am working in a highly controlled environment. When an update is available it has to be installed (backwards compatibility with the database is not ensured with old versions).

Another option is to fail the run if skip is pressed (that works fine too).

I need some way to stop them from running an old version of the application.

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
Vaccano
  • 78,325
  • 149
  • 468
  • 850

5 Answers5

44

This article answers your question. I'm pointing you to the article instead of just posting an answer because everything in the article is worth knowing.

http://www.sayedhashimi.com/CategoryView,category,ClickOnce.aspx

The following is the relevant excerpt from the article:

Forcing ClickOnce Updates

One of the big selling points of ClickOnce is automatic updates. One of the common questions I get with regard to updates is "How can I force an update on the user?"

There are three things to know with respect to forcing updates on users:

1) If your application is an online application, your users will always run the latest version; online applications get downloaded everytime the application is accessed. Thus, with online applications, you get forced-updates by default.

2) If your application is an installed application, you can force updates by using the MinimumRequiredVersion attribute. If you publish your application using Visual Studio, you can set this property from the Updates Dialog.

3) The last thing to note is that if your application is an installed application (and you have not set the MinimumRequiredVersion attribute) ClickOnce will prompt the user with an "Update Available" dialog ONLY if the user launches the application from the Start Menu shortcut. That is, if an application is an installed application and the user launches the application from a URL, ClickOnce forces the update.


I also found another good article:

ClickOnce: Bringing Ease and Reliability to Smart Client Deployment

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David
  • 72,686
  • 18
  • 132
  • 173
  • Thanks for the answers, very helpful! :) Just a note too that the sayedhashimi.com link is broken. – deadlydog Aug 14 '12 at 17:41
  • 1
    I've documented a process for automatically updating the MinimumRequiredVersion attribute when using method 2 at http://geekswithblogs.net/deadlydog/archive/2012/08/15/force-clickonce-applications-to-automatically-update-without-prompting-user.aspx – deadlydog Aug 15 '12 at 00:10
  • I've now created a NuGet package that automatically handles all of the setup/installation that the article in my comment above talks about. The NuGet package is at https://nuget.org/packages/AutoUpdateProjectsMinimumRequiredClickOnceVersion, and this blog post explains it a little more (https://deadlydog.wordpress.com/2013/03/08/force-your-clickonce-app-to-update-without-prompting-user-now-on-nuget/). – deadlydog Mar 11 '13 at 02:55
  • 3
    Here is a cached contents of the first link on a different site - http://sedodream.com/CategoryView,category,ClickOnce.aspx – Victor F Aug 21 '14 at 09:56
  • The first link seems to be broken (not in DNS?). – Peter Mortensen Mar 30 '15 at 20:28
  • "Starting in Visual Studio 2019 version 16.8, you can use the Publish tool to publish .NET Core 3.1, .NET 5, or newer, Windows Desktop applications (...)" However, the .Net version of ClickOnce is massively neutered. There is only user-prompted update (skip once, never prompt again), or forced update with the `MinimumRequiredVersion` property specifying a version. The user will not get an update prompt until a version newer than the skipped one is available, if `MinimumRequiredVersion` is &lte; than the skipped version. – Martossy Alex Oct 05 '22 at 09:10
6

This neatly worked for me. Add the following to the project file:

<UpdateRequired>true</UpdateRequired>
<MinimumRequiredVersion>$(ApplicationVersion)</MinimumRequiredVersion>

Note that ApplicationVersion cannot have a value like 1.0.0.* in the project file and it should be incremented at build time for auto-update to work.

If using TeamCity, to increment the version number go to Build Configuration page for your project and set the following System Property:

system.ApplicationVersion = %build.number%

You can also get MSBuild to increment version by time with something like this:

<UpdateRequired>true</UpdateRequired>
<BuildNumber>$([System.DateTime]::Now.ToString(yyyyMMdd))</BuildNumber>
<RevisionNumber>$([System.DateTime]::Now.ToString(mmss))</RevisionNumber>
<ApplicationVersion>1.0.$(BuildNumber).$(RevisionNumber)</ApplicationVersion>
<MinimumRequiredVersion>$(ApplicationVersion)</MinimumRequiredVersion>
orad
  • 15,272
  • 23
  • 77
  • 113
2

In addition to David's answer, simply install the AutoUpdateProjectsMinimumRequiredClickOnceVersion nuget package in your project. Once you have your project set to check for updates and to use a minimum required version, this will handle making sure the minimum required version always matches your current version (i.e. user's will always be forced to update to the latest version).

Community
  • 1
  • 1
deadlydog
  • 22,611
  • 14
  • 112
  • 118
1

It worked me by unchecking The application should check for updates, and the application started updating without prompting the user after two versions.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
PUG
  • 4,301
  • 13
  • 73
  • 115
  • 3
    This will only work if you handle Updates in code using the Clickonce API: http://msdn.microsoft.com/en-us/library/ms404263.aspx – Uri Abramson Jul 03 '13 at 08:12
  • 1
    yes my code is handling updates in Program.cs i reload the code if assembly has a newer version – PUG Jul 03 '13 at 18:05
0

To force an update on the clients you must set the minimum version field equals to the current version you are deploying, this will force the update whiout "skip" option.

Jhollman Cutcsa
  • 631
  • 7
  • 6