Automatically Install Updates Using ClickOnce Deployment

I wanted to deploy my project using ClickOnce . But when I did it like this, he asked in a dialog box on the end-user computer:

A new version of XXXX is available. Do you want to download it now?

But my end users don't have a mouse or keyboard. Therefore, I intend: it should automatically receive updates, but should not request this dialog box on the client side. How to achieve this using ClickOnce deployment?

+7
source share
6 answers

It looks like you can do this by changing some properties in the assembly.

http://blog.jnericks.com/configuring-msbuild-to-auto-update-clickonce

  • MinimumRequiredVersion - tells ClickOnce that when updating the application that it should update to this version (however, it is not necessary to click the ClickOnce button to perform the update). As you can see, we set this to the same version number for which ApplicationVersion is set so that MinimumRequiredVersion is always the latest version.
  • UpdateMode = Foreground - tells ClickOnce to update the application. before its opening.
  • UpdateRequired = True - allows ClickOnce to automatically update.

No MSBuild script:

  • Right-click your project and select "Properties"
  • Click the Publish tab in the lower left.
  • Click the "Updates ..." button to open the "Application Updates" dialog box.
  • Check "Application must check for updates"
  • Select "Before running the application."
  • Check the box for "Specify the minimum required version for this application."
  • Enter the version of the publication that you can see in the basic window of the publication as minimal. Sorry, you must change this post. Perhaps there may be a car for this.

Then publish the app and test it. This was good for me in a local test application.

Edit: it looks like some people are getting the minimum required version for an update, they might want to look into their decisions .

Edit 2: Image showing where versioning is important:

Minimum version

Also, please note that I have the checkbox "Automatically increase revision with every post." Each time you enter Properties for a project, this version will be current. Usually you just need to change the “Version” part of the version in the “Application Updates” window so that it matches the “Edition” on the “Publish” tab.

+8
source

Of course it can! While this is a network application, you can easily check for updates using this code. See below:

Private Sub InstallUpdates() Dim info As UpdateCheckInfo = Nothing If (ApplicationDeployment.IsNetworkDeployed) Then Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment Try info = AD.CheckForDetailedUpdate() Catch dde As DeploymentDownloadException (You may want to log here) Return Catch ioe As InvalidOperationException (You may want to log here) Return End Try If (info.UpdateAvailable) Then Try AD.Update() Application.Restart() Catch dde As DeploymentDownloadException (You may want to log here) Return End Try End If End If End Sub 

You can enter this fragment and call it at startup. It works in console applications, Windows Forms applications , but only in case of network deployment! Where you see all my comments about registration, where I originally used message boxes with prompts, but this is a version that does not require input!

+4
source

In addition to Gromer's answer, just install the AutoUpdateProjectsMinimumRequiredClickOnceVersion nuget package in your project. Once your project is configured to check for updates and use the minimum required version, this will mean that the minimum required version always matches your current version (i.e. the user will always be forced to update to the latest version).

+2
source

Any ClickOnce application based on a .exe file can be silently installed and updated by a special installer. The user installer can implement the user experience during installation, including customizable dialog boxes for security and maintenance operations. The custom installer uses the InPlaceHostingManager class to perform installation operations.

To implement this solution, refer to this link.

+1
source

I know this is old Q., but I will answer anyway. (hope this helps someone):

First , you need to check: Choose when the application should check for updatesAfter starting the application .

Secondly, add this method to your code:

 private Boolean isVersionOK() { UpdateCheckInfo info = null; if (ApplicationDeployment.IsNetworkDeployed) { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; try { info = ad.CheckForDetailedUpdate(); } catch (DeploymentDownloadException) { // No network connection return false; } catch (InvalidDeploymentException) { return false; } catch (InvalidOperationException) { return false; } if (info.UpdateAvailable) { try { ad.Update(); Application.Restart(); Environment.Exit(0); } catch (DeploymentDownloadException) { // No network connection } return false; } return true; } else { return false; } } 

Finally, you just need to call isVersionOK () at the beginning of your application and in each of several loops, if necessary, to check for updates. it will return TRUE if you are in its latest version, otherwise it will return FALSE and expect the application to automatically restart to a newer version without user intervention . >.

0
source

To continue Ahmed's answer, below is the code in VB.NET with minor improvements. It may not be the same as in best practices, but it is readable and descriptive.

 ''' <summary> ''' Checks if the update is available for network based deployment and download it. ''' </summary> ''' <param name="autoDownloadUpdate">If the update is available, should it be downloaded automatically.<para>Default value is <code>True</code></para></param> ''' <returns>It will return <code>True</code> only if the latest version is already installed. ''' <para>If autoDownloadUpdate is set to <code>True</code>, the update is auto downloaded (and app restarts and nothing is returned) else it returns <code>False</code>.</para> ''' </returns> Shared Private Function CheckAndDownloadUpdate(ByVal Optional autoDownloadUpdate As Boolean = True) As Boolean If ApplicationDeployment.IsNetworkDeployed = False Then Return False Dim appDeployment As ApplicationDeployment = ApplicationDeployment.CurrentDeployment Dim info As UpdateCheckInfo = Nothing Try info = appDeployment.CheckForDetailedUpdate Catch ex As Exception ' Exceptions if you want to handle individually 'DeploymentDownloadException ' No network connection 'InvalidDeploymentException 'InvalidOperationException Return False End Try ' If no update is available, it means latest version is installated If info.UpdateAvailable = False Then Return True ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' If we are here, it means an update is available on the network ' if autoDownload is False, simply return False If autoDownloadUpdate = False Then Return False Try appDeployment.Update() Application.Restart() Environment.Exit(0) Catch ex As DeploymentDownloadException ' No network connection Return False End Try End Function 

Then you can call it that in your startup code

 CheckAndDownloadUpdate() 

Any feedback to further answer the question ...

0
source

All Articles