Search code examples
c#wpfwindows-installerdesktop-application

Installation of development and production versions on the same computer


I have a stable production version of software which always has version number "1.X.0". We don't have any testing environment so I created a development version with version number "1.X.Y" for testing purposes. I test this version on production computer before releasing new production version (1.X+1.0)

This works fine, there are safety measures in place so that they cannot get mixed up. I also created automatic update for both versions using

startInfo.Arguments = string.Format("/passive /norestart /i \"{0}\"  TARGETDIR=\"{1}\"", msiPath, installDirectory);

installDirectory is different for production and development version.

The problem is this:

The upgrade code is the same for both versions. I don't want to switch between upgrade codes. I also set RemovePreviousVersion to false, because I don't want to have version 1.X.0 removed, when installing version 1.X.Y. Is it possible to have versions 1.X.0 and 1.X.Y on the same computer at the same time and when version 1.X.0 gets upgraded to version 1.X+1.0, only 1.X.0 is uninstalled? The same should apply for 1.X.Y version.

Or is there a better way to handle this? Thank you


Solution

  • I found the solution for having 2 or more different versions of the same software installed at the same time and updating them automatically.

    First I find the version I am currently using with

    var version = Assembly.GetExecutingAssembly().GetName().Version;
    

    I then compare that to the version of .msi file which is in a update folder on server (there are production and development folders). If the .msi version is higher than installed version, the upgrade begins.

    First I install the new software in the same folder using

    startInfo.Arguments = string.Format("/passive /norestart /i \"{0}\"  TARGETDIR=\"{1}\"", path, installDirectory);
    var process = System.Diagnostics.Process.Start(startInfo);
    process.WaitForExit();
    

    Then I uninstall only the version I opened. I find the product code of that specific version using below code (I found the code in Windows GUID or Application List answer and modified it a bit)

     private string GetProductCode(string programName, string version)
            {
                StringBuilder sbProductCode = new StringBuilder(39);
                int iIdx = 0;
                while (
                    0 == MsiEnumProducts(iIdx++, sbProductCode))
                {
                    Int32 productNameLen = 512;
                    StringBuilder sbProductName = new StringBuilder(productNameLen);
    
                    MsiGetProductInfo(sbProductCode.ToString(),
                        "ProductName", sbProductName, ref productNameLen);
    
                    if (sbProductName.ToString().Contains(programName))
                    {
                        Int32 installDirLen = 1024;
                        StringBuilder sbVersionString = new StringBuilder(installDirLen);
    
                        MsiGetProductInfo(sbProductCode.ToString(),
                            "VersionString", sbVersionString, ref installDirLen);
    
                        if (version.Contains(sbVersionString.ToString()))
                        {
                            return sbProductCode.ToString();
                        }
                    }
                }
    
                return null;
            }
    

    and run

    startInfo.Arguments = string.Format("/passive /norestart /x \"{0}\"", productCode);
    System.Diagnostics.Process.Start(startInfo);
    

    At the end there are still 2 installed version of the softare and only one was updated.