For technical reasons, I can't use ClickOnce to auto-update my .NET application and its assemblies. What is the best way to handle auto-updating in .NET?
views:
1871answers:
11What's the best way for a .NET winforms application to update itself without using ClickOnce?
I think the Updater Application Block was something of a precursor to ClickOnce. Might be worth investigating. Looking at its source code might be enough to spark some ideas.
Write your own.
I have heard that they are somewhat difficult to write the first time, but after that it gets simple.
Since I haven't written one yet (although its on my list), I can give you some of the things that I have thought of. Maintain accurate dll versions, as this is important for self updating. And make sure that the updater can update itself.
In your Program.cs file do something like this:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Update();
Application.Run(new Form1());
}
private static void Update()
{
string mainFolder;
string updateFolder;
string backupFolder;
foreach (string file in
System.IO.Directory.GetFiles(updateFolder))
{
string newFile = file.Replace(
updateFolder, mainFolder);
if (System.IO.File.Exists(newFile))
{
System.IO.File.Replace(file, newFile, backupFolder);
}
else
{
System.IO.File.Move(file, newFile);
}
}
}
Additionally, it can be made recursive to pick up directory structure if necessary. This will allow you to update any .dll in your project; everything, in fact, outside of the main .exe. Then somewhere else within your application you can deal with getting the files from your server (or wherever) that need to be updated, put then in the updateFolder and restart the application.
About 3-4 years ago I published an example that sits outside the app, if an update is detected, the app calls the updater ans shuts down, then the updates are done, and the app restarts.
I published the example on the old GotDotNet site...I'll have to try and find it.
It worked perfect and took about 1-2 hours to write.
Indigo Rose has a product called TrueUpdate that also does this for you. I have used them in the past from both managed and unmanaged apps. It is basically a file you put on your server (http, ftp, whatever you like). Then you call a client side EXE to check for updates. The updates file is pulled and has logic to detect what version is on the client (your choice, DLL detection, registry key reads, etc). Then it will find the appropriate updater for it and download the file for execution. It works well through proxies as well.
The only thing they don't do is actually build the patches for you. You have to do that manually, or with another product they have. It is a commcerial solution and works quite well though if you need it.
On a project a long time ago, using .NET Compact Framework 1.0, I wrote an auto-updating application. We used SqlCE's CAB deployment feature to get the files onto the device (you would use Sync Framework now), and we had a separate exe that did the unpacking of the CAB, and updating the files.
An update would go like this: the user would be prompted to update, click a button and drop out of the UI application. The updater exe would take over, get the cab file from the server, backup the current dlls and unpack the cab file with wceload. The UI would then be restarted, and if it failed, the update would be rolled back. This is still an interesting scenario on compact devices, but there are better tools now than just sqlce.
I would certainly look at updater application block and sync framework to implement this if clickonce is not an option. But I'm guessing you'll still need a separate executable because the dlls you want to overwrite are probably file locked while in use by an exe, like one of the previous answers already said.
As a starting point for rolling your own, it's probably worth looking at Alex Feinman's article on MSDN entitled "Creating Self-Updating Applications with the .NET Compact Framework".
I wrote my own autoupdater, the autoupdater uses a common config file to the application which contains urls to download latest versions from / check if it needs to update.
This way you run the updater, which either updates the app or not, then runs the application, which as part of normal operation, checks for an updated updater and patches that.
We have a product that's commercial/open source: wyBuild & wyUpdate. It has patching ability and is dead simple to use.
Edit: I'm getting voted down into the negative numbers, but my post wasn't just blatant selling. Our updater, wyUpdate, is open source, written in C# and is licensed under the BSD license.
I thought it might help anyone trying to build an updater from scratch using the .NET framework.
But, vote me down if you must.
Hi,
I want to recommend you BitsUpdater. It is simple and extendable library for automatic update process using BITS (technology used by Windows Update).
There is a sample for processes (special project called ApplicationLauncher) and you can extend library with your own solution for updating any other services (database, ...).