Free solution for automatic updates with a .NET/C# app?
From searching I can see this has been asked time and time again, but not adequately enough, so here goes. I'm a hobbyist developer with no budget. A program I've been developing has been in need of regular bugfixes, and me and users are getting tired of having to manually update.
Me, because my current solution of updating a text file through FTP and my download links on the website, and then hoping users will see the "there's an update message", and finally getting them to then be bothered to manually download the update, well quite frankly, is abysmal.
Users, because, well, "Are you ever going to implement auto-update?" "Will there ever be an aut开发者_运维百科o-update feature?" And if I happen to screw up the update process, pitchforks start arriving.
Over the past I have looked into:
- WinSparkle - No in-app updates, and the DLL is 500 KB. My current solution is a few KBs in the executable and has no in-app updates.
- .NET Application Update Component - Unfortunately I can't comprehend the documentation.
- Eduardo Olivera's AutoUpdate - This doesn't appear to support anything other than working with files that aren't in use.
- wyUpdate - wyBuild isn't free, and while the wyUpdate specification is available, it's simply too complex and time-consuming to go through.
- AppLife Update - Ditto the last sentence.
- ClickOnce - Workarounds for implementing launching on startup are massive, horrendous and not worth it for such a simple feature. Publishing is a pain; manual FTP and replace of all files is required for servers without FrontPage Extensions.
It's quite disappointing that the situation on Windows is like this when you've got really nice and simple implementations for Mac OS X like Sparkle.
Implement it yourself! It will be fun. Create a separate application that only contains update logic i.e., fetch the files online, download them, replace local files, and show that visually to the user.
So your main application could check for updates, and if they exist it would prompt the user with the possibility to update. If the user wants to, it will run the update program, close itself (so the update can happen) and presto.
The only things you need are readily avaliable in C#, FTP access and IO.
Edit: I know it's not something terribly easy, but it's a perfect chance to learn:
- How to (properly) download files, in an abstracted way that can be extended to ftp, http, etc.
- How to (properly) do a simple task over many files - copying or overwriting them (this implies error handling).
- Practice (because there's no "proper" way) to layer and encapsulate a piece of software.
- How to deal with the OS/other software (antivirus/firewall/etc) not cooperating.
These are all things we all need to know well - If it takes some weeks to code an updater it means you were needing some weeks of learning. If you don't need to learn, time to hone your skills! If you don't know if you need, time to find out! :)
Note: I know I do need to learn better file and network I/O
Should've updated this ages ago, oops!
But anyway, I've been using SparkleDotNET for a while now and it's been working absolutely wonderfully. There's a few little bugs here and there but I've already helped get some of them squashed, and hopefully I'll be able to get rid of the others too :)
For those who have the time to run the publish functionality of Visual Studio, and whose app is relatively self-contained, and doesn't require anything like launching on startup, I'd recommend ClickOnce for sure. MetroTwit uses it and it's got a nice in-app updater interface, so it seems flexible (at least to a certain degree). For launching on startup, it's possible to do so, but methods to do so are quite hacky and don't work that well.
You can try Autoupdater.NET from GitHub I developed it my self and it works very well in my applications. You just have to add one line in your code and it's done. Also, it is open source so you can modify and use as you want.
You even can not to develop an external application but implement it as your application's module, e.g. into namespace Update
, and use dynamic assembly builder to generate an exe, start it and exit app main, start it again when update will be finished.
Some more info.
There is also DDay update which is open source and is used by one of my customers. We/they are primarily interested in it in the context of a windows service at it works reasonably well for that.
For a more powerful solution, you may want to look at Google Omaha. It's what Chrome uses. You can get both in-app and automatic updates in the background when your application isn't running.
Try with MD5-Update it is absolutely free and easy no configuration need in your app only add library and publish the files. https://github.com/jrz-soft-mx/MD5-Update/
1. Your need a web server with PHP for publish your files please include updt.exe.
2. Add index.php for make list of update files. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.
<?php
$_dat = array();
$_dir=new RecursiveDirectoryIterator(".");
foreach (new RecursiveIteratorIterator($_dir) as $_itm) {
$_fil = str_replace(".".DIRECTORY_SEPARATOR, "", $_itm);
if(!is_dir($_fil) && $_fil != "index.php"){
$_dat[]=array('StrFil' => "$_fil", 'StrMd5' => strtoupper(md5_file($_fil)), 'lonSiz' => filesize($_fil));
}
}
echo json_encode($_dat, JSON_UNESCAPED_UNICODE);
?>
3. Add nuget repository at your proyect
PM> Install-Package MD5.Update
4. Call the library when your app stars, with your update folder url, update all files and download your new app on updt folder, for replace your app need updt.exe
string strUrl = "http://yourdomain.com/app/";
if (MD5Update.MD5Update.Check(strUrl, true))
{
Process.Start(AppDomain.CurrentDomain.BaseDirectory + @"updt.exe", AppDomain.CurrentDomain.FriendlyName + " " + Process.GetCurrentProcess().ProcessName);
Application.Exit();
}
5. updt.exe for replace the current app with the new app updt folder to app. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
List<string> lisArg = Environment.GetCommandLineArgs().ToList();
if (lisArg.Count < 2)
{
MessageBox.Show("Please provide App Excutable Name and Procees name");
Application.Exit();
return;
}
string strAppName = lisArg[1];
string strAppProcees = lisArg[2];
Process[] lisPro = Process.GetProcessesByName(strAppProcees);
foreach (Process Pro in lisPro)
{
if (Pro.Id != Process.GetCurrentProcess().Id)
{
Pro.Kill();
Thread.Sleep(1000);
}
}
string strAppMain = AppDomain.CurrentDomain.BaseDirectory + strAppName;
string strAppUpdate = AppDomain.CurrentDomain.BaseDirectory + @"updt\" + strAppName;
if (!File.Exists(strAppMain))
{
MessageBox.Show("App Excutable dosent exists");
Application.Exit();
return;
}
if (!File.Exists(strAppUpdate))
{
MessageBox.Show("App Excutable Updated dosent exists");
Application.Exit();
return;
}
File.Copy(strAppUpdate, strAppMain, true);
long fileSize = 0;
FileInfo currentFile = new FileInfo(strAppMain);
while (fileSize < currentFile.Length)
{
fileSize = currentFile.Length;
Thread.Sleep(1000);
currentFile.Refresh();
}
Process.Start(strAppMain);
}
catch (Exception Ex)
{
MessageBox.Show("An error ocurred");
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"updt_" + DateTime.Now.ToString("yyyyMMddTHHmmss") + " .txt", Ex.ToString());
Application.Exit();
}
all guys are right specially look at the abatishchev reply.but i think some thing other need that guy forgot it. try to develop your project "modular".put them your code in class library as you can.so during the fix operation replace one of them.think a bout database fix.some time you need to add a column to your database table.what do you do for these cases?
a have developed an update project.in that , i have three kind of fixes. 1- BUG in program operation and need to replace a DDL file 2- Bug in program and need to update currently program executive file 3- bug or change the database and need to execute a sql server query
in a table on web host i put the version history and every time that my app start check for new version.if any update exist check for its type and download it and do the suitable action depend on the update kind and parameters
good luck dude
精彩评论