Dennis van der Stelt

I care about technology; I care about users more

Community

Email Notifications

News

  • Addicted to Refactor! Pro
    <div class="sideNavItems">

I read...

I Use...

Tags

Recent Posts

Archives

Blog Subscription Form

  • Email Notifications
    Go

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.

Comments

Aaron said:

Thanks for this solution. Worked like a charm.
# April 11, 2006 11:29 AM

fedrok said:

Dennis! You're mithycal! For 2 days I've broken my head against wall... Thx!
# November 9, 2006 6:43 AM

Dennis van der Stelt said:

Hehehehe, you're welcome :)

# November 9, 2006 6:53 AM

sinm said:

thanx. for my request your page was first in list in google
# November 13, 2006 12:56 PM

F£ö said:

Thanks a lot, works great

# November 27, 2008 5:05 PM

krishna said:

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.

# January 21, 2010 10:15 AM

Dennis van der Stelt said:

@krishna : Have you read this article?

bloggingabout.net/.../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.

# January 25, 2010 2:35 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 3 and 3 and type the answer here: