Click here to Skip to main content
Click here to Skip to main content

Adding automatic updates to your program - Part 1

By , 31 Dec 2007
 

Introduction

In today's world, applications are quickly moving towards a simple, all-encompassing distribution model. Web applications are gaining popularity because of their scalability and ease of deployment, and desktop applications are becoming less common. This holds both positive and negative consequences - mainly with functionality and user experience.

Most applications need to ensure the best user experience possible for any given situation. In many cases, a web site meets the needs of both the developer and the consumer. However, some applications are better suited as a client-side, distributed application.

For these applications, the need arises for an easy and reliable method of deployment that allows the application the flexibility for any scenario. It should gracefully handle updates to the application, and be easily managed remotely. For this reason, DDay.Update came into existence - to provide an easy interface for adding automatic update functionality to your application, avoiding most of the headache involved in the update process, while allowing the most flexibility possible.

Background

The technology that will be presented uses Microsoft's ClickOnce publishing mechanism that is built into Visual Studio 2005. It does not use ClickOnce itself. This is for many reasons:

  1. It's difficult to use your own deployment methods (use Windows Installer, for example) and still use ClickOnce for automatic updates.
  2. You cannot easily update individual files with ClickOnce, it's an all-or-nothing update, by default. This becomes problematic when your application is anything but very small in size, or you have very few users.
  3. To use a different GUI with ClickOnce requires a complete, built-by-hand interface. DDay.Update's GUI is pluggable. There is currently a pre-built interface for Windows Forms 2.0, and one will soon be available for .NET 3.0 (WPF).
  4. DDay.Update does not interfere with your application's security permissions.
  5. Open source applications lend to a better understanding of the underlying technology. Since DDay.Update and all its controls are open source, you are free to study and extend the code.

That said, if you haven't already, I encourage you to give ClickOnce a try. You may find that it suits your needs. When you find some of its features lacking, then give DDay.Update a try.

Note: DDay.Update is not a wrapper for ClickOnce. It simply consumes ClickOnce manifest files.

OK, what now?

In this article, I will present a bare-bones application, and give it automatic update functionality.

Preparation

First, download the most recent binary version of DDay.Update from SourceForge.net. It is also included in this article for convenience.

Once downloaded, you're ready to begin.

We will now go through the following steps:

  • Step 1 - Create an application to be automatically updated
  • Step 2 - Publish the application
  • Step 3 - Create a Bootstrap application
  • Step 4 - Test it out

Step 1 - Create an application to be automatically updated

Create a new Console project in Visual Studio. Click File->New->Project, and select "Console Application" from the list. I named mine "AutoUpdatingApplication". You can choose whatever name you'd like (though it may be easier to follow examples if you use the same name).

Add a basic line of code to this application, such as:

Console.WriteLine("This is my application.");

Step 2 - Publish the application

We will use Visual Studio's ClickOnce mechanism to publish this simple application. This process is very simple. If you already know how to publish a ClickOnce application, skip to Step 3.

First, right-click on your console application project, and select "Properties".

Screenshot - ProjectProperties.png

Then, click on the "Publish" tab on the left, and click the "Publish Wizard" button:

Screenshot - PublishTab.png

Then, follow the steps of the wizard. Here's what I did:

Screenshot - PublishWizardStep1.png

Screenshot - PublishWizardStep2.png

PublishWizardStep3-1.png

Click "Finish", and your application should now be published to the location you indicated in the first step of the wizard. In my case, it's "C:\Deployment\DDay.Update.Test".

That's it, your application should now be published through ClickOnce!

Step 3 - Create a Bootstrap application

DDay.Update uses a bootstrap application to "mimic" the look and feel of your "real" application. In order to create this Bootstrap application, you need to use the Configuration Tool included in the binary distribution of DDay.Update.

First, open the Configuration Tool that you downloaded in the Preparation step of this example. Then, select File -> Open Deployment Manifest.

ConfigToolOpenDMFromFile2.png

You will then see the following screen:

ConfigToolOpenDMFromUrl_ChooseUrl.png

Enter the location where you published your application. This will include the name of your project, with a .application extension. In my case, it's:

C:\Deployment\DDay.Update.Test\AutoUpdatingApplication.application

Then, click Open. You will then see the main configuration screen, with some information automatically determined. The Update URI should already be provided - if it isn't, it should match the location where you published your application. In my case, it's C:\Deployment\DDay.Update.Test. When an Update URI is provided, you can click the "Verify URI" button to ensure that the URI is valid:

ConfigToolUpdateURI_Validate2.png

Then, choose an update notifier. This is the "pluggable" GUI that DDay.Update uses to display update information to the user.

Afterwards, choose a destination folder for the Bootstrap application to be created. I added a new folder on my desktop:

Screenshot - ConfigToolDestFolder.png

When you've completed these steps, you're ready to build the Bootstrap application. Click the "Create Bootstrap" button, and you should see a message as follows:

Screenshot - ConfigToolBootstrapSuccess.png

Then, the destination folder will automatically open, and you'll see your brand-new Bootstrap! If you run the executable in that folder, you'll see your application download the most-recent version and run it, and your folder will look like this:

Screenshot - ConfigToolDestFolderOpened.png

Notice the folder named "1.0.0.0". That's where your "real" application is stored.

Congratulations, you've setup your application to automatically update!

Step 4 - Test it out

To see the update in action, open Visual Studio again, and publish a new version of your application. Then, go back to the "destination folder" where you created your Bootstrap, and run the application. You should see a message as follows:

Screenshot - Bootstrap_UpdateAvailable.png

Select "Upgrade Now", and the new version will download and run. You'll also notice that the directory structure of your application looks like this:

Screenshot - ConfigToolDestFolderOpenedUpgraded.png

Notice the new "1.0.0.1" folder. The new version of the application has been placed here.

Note: If you chose "Upgrade Later", version 1.0.0.0 will be run, and no updating will occur.

That's it!

Your application is now automatic-update-enabled.

Important information

When you distribute your application to your users, simply give them the Bootstrap application instead of the "real thing", and they will always receive automatic updates. You can even deploy your applications to your users through this method - no need to have them download your large application all at once. They can download the bootstrap application, and it will download the rest.

Points of interest

DDay.Update is in mid Beta testing. If you see anything strange or unexplained, please let me know by submitting a bug report here.

History

  • 12/31/2007 - Article updated (Version 0.63)
  • 11/13/2007 - Article updated (Version 0.61.1)
  • 11/12/2007 - Article updated (Version 0.61)
  • 07/23/2007 - Article updated
  • 07/16/2007 - Initial revision (Version 0.52)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Douglas Day
Web Developer
United States United States
Member
Doug has been a Software Engineer for 7 of the previous 9 years, and has 12 years of programming experience.
 
For the past 3 years, he has been developing custom applications in C# and Visual Basic.NET, with an emphasis on custom cross-Internet applications for IT management, real-time collaboration, and process management and reporting.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionChange "Update now" button textmemberwelcometi4 Sep '11 - 7:21 
Hello, i cant find the code where i can change buttons text. I want to change "Update now" and "Later" buttons text.
Anyone help, pls.
QuestionError when create bootstrapmemberm_466030 Jul '11 - 15:21 
Hello, i've been looking how to make my application will automatically update and found this article.
I follow the whole steps like yours, but when i want to create bootstrap with DDay.Update Configuration Tool it appears error message.
 
Could not load type
'System.Runtime.Versioning.TargetFrameworkAttribut' from assembly 'mscorlib, Version=2.0.0.0, Cultur=neutral, ... '
 
I don't understand about that, please help me about this deployment because i really need it.
AnswerRe: Error when create bootstrapmemberKananiKinjal18 Jan '12 - 23:06 
Could not load type
'System.Runtime.Versioning.TargetFrameworkAttribut' from assembly 'mscorlib, Version=2.0.0.0, Cultur=neutral, ... '
Even I am getting the same error any solution for it..???
GeneralUsing IP Addressmembershaker_natour15 Jun '11 - 19:56 
can i use IP address for server name
for example
 
\\SeverName\ApplicationName.application
\\172.161.1.\ApplicationName.application
QuestionInvalid value for 'Update URL'. The string must be a fully qualified URL or UNC path ..."memberankitpsaraogi26 Mar '11 - 9:40 
I was following your artical using the exact file names and paths. When setting up the clickOnce publish properties (using Publish Wizard) I get a warning message when entering "C:\Deployment\DDay.Update.Test" as the place where the application will look for updates, this prevents me from going any further. The warning reads:
 
"Invalid value for 'Update URL'. The string must be a fully qualified URL or UNC path ..."
 
Any ideas why this works for you guys and not me? I'm using VS 2008.
AnswerRe: Invalid value for 'Update URL'. The string must be a fully qualified URL or UNC path ..."memberLubos111 May '11 - 9:01 
I have the same problem. Have you got any fix? I use VB 2010 Express. Thank you.
Thanks.
Lubos

GeneralRe: Invalid value for 'Update URL'. The string must be a fully qualified URL or UNC path ..."memberDouglas Day11 May '11 - 9:02 
Try using "file:///c:/Deployment/DDay.Update.Test" perhaps?
-Doug
GeneralRe: Invalid value for 'Update URL'. The string must be a fully qualified URL or UNC path ..."memberLubos112 May '11 - 5:48 
Thank you. I'll try it.
Thanks.
Lubos

GeneralRe: Invalid value for 'Update URL'. The string must be a fully qualified URL or UNC path ..."membervera_t29 Feb '12 - 2:28 
It doesn't help me in VS 2010 Ultimate version. What can I do with this?
Questionboot strap?membervlad7813 Feb '11 - 12:56 
where do i find that?
Questionwhat server should i use?memberangels77721 Dec '10 - 14:08 
hi may i know what server should i put all my .dll in? Can i upload it to the apache server?
QuestionRemoving Files ?membertotor351 Dec '10 - 20:59 
I discover your well done project.
Congratulations !
 
I'm trying some kinds of test to see if it is correct for me.
An i don't know if is it a normal behaviour but if for example you have some binary files include in your manifest in the version 1.0.0.8 for example... If you see that one binary file is no more needed, you can remove it from the next published version (1.0.0.9)... But when the dd update occurs, i always see this binary files in the 1.0.0.9 local updated directory.
It is normal ?
A file can not be removed ? DD update does not see that a file is removed from the manifest file ?
AnswerRe: Removing Files ?memberDouglas Day2 Dec '10 - 5:42 
totor,
 
There are many cases when removing a file from the manifest doesn't always mean you want to remove it from the files in the user's distribution. If you want to remove files in the update process, check the 'Remove' tab in the 'Options' page of the Configuration Tool (when you create your bootstrapper).
 
Once you've done this, you'll need to update your bootstrapper along with your application. To do that, add a folder named "Bootstrap" in your Visual Studio project, and add all the bootstrapper files to this folder (DDay.Update.DLL, YourApplication.exe, YourApplication.exe.config, log4net.DLL, etc.). You'll need to set the build action on these items to "Content". Then, somewhere in your code (preferrably first thing) call:
UpdateManager.UpdateBootstrapFiles();
You'll need to add a reference to DDay.Update in your project to do this. This will update your bootstrapper files, and the next time the user runs your application (using the new bootstrap), the files will be deleted. This is a useful method to be able to update the DDay.Update.DLL files, along with adding/changing features of the bootstrap.
 
Let me know if you have more questions,
-Doug
QuestionBootstrap Problem at win7 UltimatememberUndercoverx20 Nov '10 - 3:11 
Hello,
im trying to Bootstrap my Application for Updating it.
 
here the Screenshots of the two Errors:
http://img87.imageshack.us/img87/195/prob1o.png
http://img198.imageshack.us/img198/1663/prob2c.png
GeneralI don't use clickonce to publish my app, I use a setup project.memberKyferEz6 Nov '10 - 20:17 
Can this still work using a setup project instead of a clickonce deployment?
Questionwindows app and windows service in one solutionmemberckdp25 Sep '10 - 21:46 
Hi Doug
 
first, thanks for a great article!
 
I have a question about windows services. I have an application made out of two parts, a windows app as the front end or manager and a windows service that does the work in the background. I would like to install them both together in one installation process (can be done by setup deployment project), but I would have liked to use clickonce because of the updates functionality. Unfortunately windows services cannot be installed by clickonce. My question, will your method work for me? If so, I assume it will be implemented seperately for each application?
Thanks in advance!
 
Regards,
CK
AnswerRe: windows app and windows service in one solutionmemberDouglas Day27 Sep '10 - 15:42 
CK,
 
I've implemented an update method for Windows Services, but it's only been very lightly tested. In this case, you'd have a bootstrap for your main application, and also setup your Windows Service to auto-update. This means you'd be publishing 2 separate applications. Your Windows Service wouldn't have a bootstrap (since it's a service, after all), but the update process I've established seems to work. You'd need to make sure the Windows Service runs on an account that has privileges to modify files in the directory where the service resides. Check out the DDay.Update.WindowsServices and DDay.Update.WindowsServices.ServiceUpdater projects from the code trunk in SVN for more information on how this is done.
 
Let me know if you have more questions.
 
Thanks!
-Doug
GeneralRe: windows app and windows service in one solutionmemberckdp28 Sep '10 - 3:22 
Thanks Doug. Do you possibly have a link to it?
 
Regards,
CK
QuestionHow to update multiple projects in a single solutionmemberNISM190623 Sep '10 - 8:15 
I was wondering if it were possible to apply this to multiple projects in the same solution? If so then how? Would this have something to do with the deployment of the solution. ex. I have proj1 and proj2 contained in a solution in VS2005 and I want to deploy them together at the same time I want to update them as the files are changed. Would I have to create separate bootstraps for each application?
AnswerRe: How to update multiple projects in a single solutionmemberDouglas Day23 Sep '10 - 9:09 
I usually deploy a single project that references multiple .dlls (i.e. projects). When you deploy that project, it also deploys information about these .dlls so they can be properly updated as well. You only want a bootstrap for concrete (runnable) applications.
 
Let me know if you have more questions.
-Doug
GeneralRe: How to update multiple projects in a single solutionmemberNISM190623 Sep '10 - 10:34 
Thanks for the quick response.
 
Doug,
 
I do the same thing as far as creating libraries and assemblies, however, in this one instance I have two separate projects that are executables (not dll's). I was thinking that maybe I could create the bootstraps for both and then create a setup project that includes the bootstraps and so, once the user runs setup project the first time, he or she will then have the bootstrap versions and they will auto-update each time from that point on.
 
I'll try it out and let you know. Unless, you have a better solution.
 
Again, thanks for the quick response.
 
Rob
GeneralRe: How to update multiple projects in a single solutionmemberDouglas Day23 Sep '10 - 10:37 
Rob,
 
Yep - you're on the right track. Each executable should have its own bootstrap. Let me know if you have any more questions.
 
Regards,
-Doug
QuestionHow to change a name of new version destenation folder? [modified]memberAndrushko2 Sep '10 - 4:46 
Where in the source code or in options you can change the name of the directory where the files are downloaded the new version?
For example: "C: \ MyAppBootstrapFolder \ 0.0.2.8 \ ..." replace with "... \ C: \ MyAppBootstrapFolder \ NewVersion \ ..."
That is, the directory is entitled "... \ 0.0.2.8 \ ..." I want to change the name to "... \ NewVersion \ ..." How to do it?

modified on Friday, September 3, 2010 12:09 PM

GeneralRe: How to change a name of new version destenation folder?memberDouglas Day2 Sep '10 - 4:51 
Currently you can't change the name of the destination folders - they are stamped with the version they represent.
 
If you're interested in contributing to the project to add this kind of functionality, let me know Smile | :)
 
Regards,
-Doug
QuestionRe: How to change a name of new version destenation folder?memberAndrushko2 Sep '10 - 5:03 
Thank you for your reply!
Help me please with code section, which is responsible for stamping of destination folders with the version they represent. So in which sourse file and which method is responsible for this action?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 31 Dec 2007
Article Copyright 2007 by Douglas Day
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid