Back in 2007 I did a post called Making your Application Automatically Update Itself. Yesterday I was pairing on a little startup I'm doing on the side with Greg Shackles and it was time do the setup application. I thought about WiX, I thought about InstallShield, but then discovered a wonderful little gem of a setup application called Inno Setup by Jordan Russell. It's free, but it's a joy and you should donate if you use it.
It took me just 15 minutes to make a simple installer, and it's clear that this tool is deep and broad in its support. However, there's no free lunch when it comes to auto-updating. Inno Setup will upgrade my app from build to build when I run a new setup over the top of an old one. I still need my app to notify the user that it's time to upgrade.
This is our little 10 minute solution, but it's actually working very nicely. Inside the latest.txt files is a simple version string like 0.9.9.4.
var http = new HttpClient();
string versionString = await http.GetStringAsync(new Uri("http://www.hanselman.com/SecretStartup/latest.txt"));
Version latestVersion = new Version(versionString);
//get my own version to compare against latest.
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
Version myVersion = new Version(fvi.ProductVersion);
if (latestVersion > myVersion)
{
if (System.Windows.MessageBox.Show(String.Format("You've got version {0} of SecretStartup for Windows. Would you like to update to the latest version {1}?", myVersion, latestVersion), "Update MyEcho?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
Process.Start("http://www.hanselman.com/blog");
}
}
I'm thinking:
- We'll add an SSL certificate and confirm its identity on the HTTP call as a little added security.
- Error Handling, natch.
- One could also download the setup app to %temp%, check it's SHA hash, launch it and close myself. Not sure I like it this automatic, though.
- Maybe only check the version once a day or once every few days.
Comments?
Sponsor: Big thanks to Red Gate for sponsoring the blog feed this week. Check out the Free Starter Edition of their release management tool! Deploy your SQL Server databases, .NET apps and services in a single, repeatable process with Red Gate’s Deployment Manager. Get started now with the free Starter Edition.
© 2014 Scott Hanselman. All rights reserved.