ClickOnce issues

I’m having a fair amount of trouble with ClickOnce, now I’m actually using it. I’m researching how updates can be user initiated. Some problems are simply solved be restarting Visual Studio 2005. One problem however is a bit less obvious.
 
UpdateLocation
It’s real easy to reproduce the error. Create a new project, preferably a Windows Application. Now add a new reference to System.Deployment and add the following using statement to your form.
 
using System.Deployment.Application;

Add a button to the new form, double click it and add the following code.

 

if (ApplicationDeployment.IsNetworkDeployed)

{

      ApplicationDeployment appDeploy = ApplicationDeployment.CurrentDeployment;

      if (appDeploy.CheckForUpdate())
      {

            MessageBox.Show("Updating app, when done, I’ll restart.");

            appDeploy.Update();

            Application.Restart();

      }

}
 

Now go to your project properties, to the Publish tab and choose the Updates button. Then disable the “The application should check for updates” checkbox. This way, we can specify when the application should update ourselves.
 
Now publish the application, install it from the webpage and it’ll run automatically. Press the button and you’ll be presented with a great dialog box, but not our own!
 
Application cannot be updated programmatically unless the deployment manifest includes the <deploymentProvider> element.
 
That’s the error you’ll be presented with. To fix it, go to the publish tab in your project configuration again, press the Updates button and specify an update location. This location should only be specified if the publish location is different, but specify the exact same location, publish, install via web page, run the app and press the button again. You’ll see your problem is fixed.
 
In another post I’ll talk a bit more about security issues in ClickOnce, as this puzzled me a bit as well. Although there’s extensive documentation, most just lightly touched the subject I wanted more info about.

You may also like...

7 Responses

  1. Aaron says:

    Thanks for this solution. Worked like a charm.

  2. fedrok says:

    Dennis!
    You’re mithycal!
    For 2 days I’ve broken my head against wall…

    Thx!

  3. Hehehehe, you’re welcome 🙂

  4. sinm says:

    thanx. for my request your page was first in list in google

  5. F£ö says:

    Thanks a lot, works great

  6. krishna says:

    Hi,

    I’m encountering a strange error with clickonce smart updated. I’ve used the code and when i publish for the first time, its fine. But, when i publish for second time, and try to run the application, from the Start Menu shortcuts, now the application should update itself, but is not doing so and simply the older version is getting again.

  7. Dennis van der Stelt says:

    @krishna : Have you read this article?
    https://bloggingabout-linux.azurewebsites.net/blogs/dennis/archive/2007/11/05/manual-check-for-updates-with-clickonce.aspx

    It describes how you can check for updates yourself, also because ClickOnce doesn’t always report there’s an update. Quite weird, but the solution provided in the link ALWAYS works.

Leave a Reply

Your email address will not be published. Required fields are marked *