Search code examples
c#visual-studio-2015backupupgradeinstallation-package

Creating a C# installation package that backs up the previous version before updating.


I am trying to create an installation program that will backup the previous version of a C# program before updating it. I'm using VS 2015, and have looked at the installer, advanced installer and InstallShield LE. I don't really know what I'm looking at, how to use custom actions, pretty much anything. Any advice or help would be appreciated.


Solution

  • Let me explain a few things first.

    Backing up the previous version

    Firstly,you need to identify your current application's installation folder.You can create a registry key to save where the application is installed(You need to do this in the first-time installer of your application).For that you can use Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ProductName\appPathHere").Then,in your new installer,you can read the registry key to get the path of the application.Then,what you can do is create a ZIP of that path/folder.For that you can use :

      System.IO.Compression.ZipFile.CreateFromDirectory(pathofApp, zipFilePath);
    

    This will backup the current application.You can even modify the file type/extension to give it your custom type/extension.

    Installing the application

    Read the registry key to get the path of the installed file.Delete it using System.IO.Directory.Delete(path, true).You can ZIP all your files and then make your installer extract it to the specific location.You can simply use :

     System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);
    

    Creating the installer

    I suggest you create a winform or WPF application,design the UI and implement the above methods.

    This is not the ideal way but it will give you an idea on how to get it done with basic knowledge.Hope it helps you