How to automatically update an application without ClickOnce?

偶尔善良 提交于 2019-12-17 17:36:10

问题


For the project I am working on, I am not allowed to use ClickOnce. My boss wants the program to look "real" (with an installer, etc).

I have installed Visual Studio 2012 Professional, and have been playing around with the InstallShield installer, and it definitely makes nice installers, but I can't figure out how to enable the application to "auto-update" (that is, when it starts up, checks to make sure that it is using the latest version).

I have been asked to make a tiny change to the code - switching an addition to a subtraction, and I don't really want people to have to uninstall the old version, and then have to reinstall the new version every time I make a small change like this.

How can I make the application check for updates, and install them? Or is this not possible (or not easy)?


回答1:


There are a lot of questions already about this, so I will refer you to those.

One thing you want to make sure to prevent the need for uninstallation, is that you use the same upgrade code on every release, but change the product code. These values are located in the Installshield project properties.

Some references:

  • Auto update .NET applications
  • Auto-update library for .NET?
  • Auto update for WinForms application
  • Suggest a method for auto-updating my C# program
  • Automatic update a Windows application



回答2:


I think you should check the following project at codeplex.com http://autoupdater.codeplex.com/

This sample application is developed in C# as a library with the project name “AutoUpdater”. The DLL “AutoUpdater” can be used in a C# Windows application(WinForm and WPF).

There are certain features about the AutoUpdater:

  1. Easy to implement and use.
  2. Application automatic re-run after checking update.
  3. Update process transparent to the user.
  4. To avoid blocking the main thread using multi-threaded download.
  5. Ability to upgrade the system and also the auto update program.
  6. A code that doesn't need change when used by different systems and could be compiled in a library.
  7. Easy for user to download the update files.

How to use?

In the program that you want to be auto updateable, you just need to call the AutoUpdate function in the Main procedure. The AutoUpdate function will check the version with the one read from a file located in a Web Site/FTP. If the program version is lower than the one read the program downloads the auto update program and launches it and the function returns True, which means that an auto update will run and the current program should be closed. The auto update program receives several parameters from the program to be updated and performs the auto update necessary and after that launches the updated system.

  #region check and download new version program
  bool bHasError = false;
  IAutoUpdater autoUpdater = new AutoUpdater();
  try
  {
      autoUpdater.Update();
  }
  catch (WebException exp)
  {
      MessageBox.Show("Can not find the specified resource");
      bHasError = true;
  }
  catch (XmlException exp)
  {
      bHasError = true;
      MessageBox.Show("Download the upgrade file error");
  }
  catch (NotSupportedException exp)
  {
      bHasError = true;
      MessageBox.Show("Upgrade address configuration error");
  }
  catch (ArgumentException exp)
  {
      bHasError = true;
      MessageBox.Show("Download the upgrade file error");
  }
  catch (Exception exp)
  {
      bHasError = true;
      MessageBox.Show("An error occurred during the upgrade process");
  }
  finally
  {
      if (bHasError == true)
      {
          try
          {
              autoUpdater.RollBack();
          }
          catch (Exception)
          {
             //Log the message to your file or database
          }
      }
  }
  #endregion



回答3:


The most common way would be to put a simple text file (XML/JSON would be better) on your webserver with the last build version. The application will then download this file, check the version and start the updater. A typical file would look like this:

Application Update File // An unique string that let your application recognize the file type

version: 1.0.0 // latest assembly version

download: http://yourserver.com/... // A link to the download version

redirect: http://yournewserver.com/... // I used this field in case of a change in the server address. This would let the client know that they need to be looking at a new address.

You can also add other important details.




回答4:


This is the code to update the file but not to install This program is made through dos for copying files to the latest date and run your program automatically. may help you

open notepad and save file below with ext .bat

xcopy \\IP address\folder_share_name\*.* /s /y /d /q  
start "label" /b "youraplicationname.exe"



回答5:


A Lay men's way is

on Main() rename the executing assembly file .exe to some thing else check date and time of created. and the updated file date time and copy to the application folder.

//Rename he executing file
System.IO.FileInfo file = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

System.IO.File.Move(file.FullName, file.DirectoryName + "\\" + file.Name.Replace(file.Extension,"") + "-1" + file.Extension);

then do the logic check and copy the new file to executing folder



来源:https://stackoverflow.com/questions/12787761/how-to-automatically-update-an-application-without-clickonce

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!