0

I'm having issues seeing how ClickOnce knows how it compares files and how it looks for those files. I will be having my ClickOnce application connect to a server, but does it do this internally?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
appel
  • 53
  • 5

2 Answers2

0

You will find everything you need in Publishing ClickOnce Applications (MSDN).

From How to: Check for Application Updates Programmatically Using the ClickOnce Deployment API:

  1. Create a new Windows Forms application using your preferred command-line or visual tools.
  2. Create whatever button, menu item, or other user interface item you want your users to select to check for updates. From that item's event handler, call the following method to check for and install updates.
private void InstallUpdateSyncWithInfo()
{
    UpdateCheckInfo info = null;

    if (ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

        try
        {
            info = ad.CheckForDetailedUpdate();

        }
        catch (DeploymentDownloadException dde)
        {
            MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
            return;
        }
        catch (InvalidDeploymentException ide)
        {
            MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
            return;
        }
        catch (InvalidOperationException ioe)
        {
            MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
            return;
        }

        if (info.UpdateAvailable)
        {
            Boolean doUpdate = true;

            if (!info.IsUpdateRequired)
            {
                DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
                if (!(DialogResult.OK == dr))
                {
                    doUpdate = false;
                }
            }
            else
            {
                // Display a message that the app MUST reboot. Display the minimum required version.
                MessageBox.Show("This application has detected a mandatory update from your current " + 
                    "version to version " + info.MinimumRequiredVersion.ToString() + 
                    ". The application will now install the update and restart.", 
                    "Update Available", MessageBoxButtons.OK, 
                    MessageBoxIcon.Information);
            }

            if (doUpdate)
            {
                try
                {
                    ad.Update();
                    MessageBox.Show("The application has been upgraded, and will now restart.");
                    Application.Restart();
                }
                catch (DeploymentDownloadException dde)
                {
                    MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
                    return;
                }
            }
        }
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Magnus Karlsson
  • 3,549
  • 3
  • 31
  • 57
  • i see that CLickOnce can check to see if there is an update for itself, but if i want to use ClickOnce to check for a software update and have the app prompt the user for the update, if Clickonce does this internally or if it is an external procedure that is needed to do this – appel Mar 15 '13 at 21:00
  • @appel Here you go. It's a complete example to do just that. Please mark this answer as accepted if you think it answers your question. – Magnus Karlsson Mar 16 '13 at 09:17
  • Does this work on Windows 7 (and Windows 8)? Isn't an exception thrown related to [User Account Control](http://en.wikipedia.org/wiki/User_Account_Control)? – Peter Mortensen Nov 17 '13 at 23:23
0

If you don't want to do programmatic updates, set "check for update before running" in the Update dialog (click Updates on the Publish screen). Then when you publish a new version, it goes in the same folders as the original deployment. When the user runs the application, it will check to see if there is an update, and it will ask him if he wants to install it. At that point, the user can skip it, or accept the update.

If you make the minimum version (in the updates dialog) equal to the version your are deploying, it won't ask him, it will just update the application.

If he skips the update, he won't see it again for a couple of weeks, if ever. Microsoft says 2 weeks, but I'm not convinced that it ever comes up again, so he might have to wait until the NEXT update or go and install the new one manually.

RobinDotNet
  • 11,723
  • 3
  • 30
  • 33