Setup project does not uninstall previous version RRS feed

  • Question

  • Hello,

    I am using Visual Studio to build an installer for my application. I am using a "windows installer setup project" (as opposed to clickonce).

    My purpose is to create an installer (msi or exe) which automatically detects and uninstalls the previously installed version of the application, then installs the new version. I can't find a way to do it. Depending on how I set the "product code", the resulting .msi file either does not recognize that a previous version is already installed, or it does recognize it but asks to uninstall the previous version manually. Neither behavior is acceptable for my product manager.

    This is what I am doing in Visual Studio's properties panel related to the setup project:

    1) set "DetectNewerInstalledVersion" to true. (I also tried false, to no avail)

    2) set "RemovePreviousVersions" to true.

    Then, each time I build a new version:

    1) I increment the "Version" property. For example, I increase it from 1.0.15 to 1.0.16. ( I also tried from 2.0 to 3.0 and the result is the same)

    2) then a Visual studio dialog box appears which strongly suggests me to change the "product code". Depending on whether I choose "yes" or "no", I get different problems:

    2.1) If I accept to change the product code, then, when I double-click on the resulting msi or exe installer, the installer does not detect the previously installed version. It tries to overwrite the files in the previous version, it fails to overwrite the exe file, and the resulting application crashes at startup.

    2.2) If, on the other hand, I do _not_ change the product code, then, when I double-click on the resulting msi or exe installer, the installer _does_ detect the previous version, but a dialog box asks me to uninstall it from the control panel first, then relaunch the installer. I need the uninstall to be automatic, without having to open the control panel.


    Ironically I have discovered that, if I install the application by right_clicking on the setup project inside visual studio, and then choose "install", the installer behaves correctly: it automatically detects and uninstalls the previous version, then installs the new version. Why is that not happening when I double-click on the generated .msi or .exe files?

    Thanks a lot for any help.
    Monday, May 25, 2009 12:03 PM

All replies

  • Any solution to this? I have the exact same results you do.

    Wednesday, July 22, 2009 7:54 PM
  • Brian,
    I have had same problem. Each time you make a change to your application, change the version # in the setup project.
    It will warn against it but click 'Yes" anyway. GL
    Sunday, July 26, 2009 5:19 PM
  • I have found a partial solution: at each new release, increment the version of each assembly (dll and exe) in  the project. You can do this by right-clicking on each project in visual studio -> properties -> application -> assembly information -> increment assembly version and file version.

    Also, when asked whether to increase the product code, choose yes. That way, the installer will always succeed in overwriting the previously installed dlls.

    However, the old installation is not actually removed, only correctly overwritten. So problems arise if the user installs a new version choosing a different path. The correct behavior would be for the msi to to first uninstall the previous version, something I can't see how to achieve.
    • Proposed as answer by Amol_B Wednesday, September 2, 2009 7:00 AM
    Monday, August 17, 2009 8:58 AM
  • Maurizio ,

    I was facing the same problem . Thank you for sharing above information.
    Wednesday, September 2, 2009 7:02 AM
  • Hi  Maurizio Colucci,

    Any luck so far ?

    I am also in the same situation.  Googling all around...
    Please share if you got a solution.

    Thanks and  Regards
    Anil Marar
    Wednesday, November 18, 2009 5:21 AM
  • Hi Maurizio Colucci,

           I know this is an old post! I'm running into the same issue that you have described in your original post. Please let me know how you resolved it.

    Thanks a lot!!!

    Thursday, December 13, 2012 10:29 PM
  • I'm having the same problem.
    I've tried everything ... the "Upgrade Code" is correct, the "Product Code" has been changed and the version of the program has increased.
    It seems that this feature does not work properly.
    If anyone has the solution, please post here
    Wednesday, January 2, 2013 7:26 PM
  • Seems to me you need to do 3 things:

    Change the version of the project itself: In Solution Explorer, right-click the main (not setup) project, choose "Properties". When the project's properties become visible, choose the "Application" tab, and click the "Assembly Information..." button.  I believe you need to change both the Assembly Version and File Version items so they both match.

    Change the version in the setup project:  Click on the setup project, and in the properties window, scroll down to the bottom and change the "Version" value TO MATCH THE VERSION YOU SPECIFIED IN THE PRIOR STEP.  When the "It is strongly suggested..." dialog comes up, choose Yes or OK.  Note:  There are 4 segments to a project version, but only 3 segments to a setup project version.  I believe the 3rd segment of the project version is equivalent to the 3rd segment of the setup version, and the 4th segment is ignored, so keep this in mind when matching the versions.

    This may be obvious, but it's bit me a couple of times:  Go into configuration manager from the Build menu, and make sure both the main project and the setup project are checked on in the "Build" column.  Do this for both Debug and Release versions.

    This has worked for me in the past, but not if I left out any of the steps above.

    Ron Mittelman

    • Proposed as answer by Wiccio Tuesday, June 13, 2017 3:50 PM
    Monday, July 15, 2013 9:04 PM
  • Hi,

    You can always save the last installation path (in a os var or some specific path) and if the new changes go for a different path unistall the previous version (deleting all data in path??).
    this is just an ideia, you probably would have to code this but could solve your problem.

    NOTE: after the installation of the new version don't forget to update the os var or file where you saved last installation path.

    Monday, February 17, 2014 12:19 PM
  • After many tests and many tutorials readed, this has finally worked! Thanks so much!
    Tuesday, June 13, 2017 3:50 PM
  • If you change your setup project version, which is available at button of pane while right click on setup project properties, your problem will be solved.
    Tuesday, June 12, 2018 10:59 AM
    Maurizio Colucci thank you, your solution worked for me.
    • Edited by Ryan-T93 Wednesday, January 9, 2019 3:13 PM
    Wednesday, January 9, 2019 12:24 PM
  • For those who are facing this issue now, you can try

    1. Set DetectNewerInstalledVersion to True and RemovePreviousVersions to True in project properties

    2. increment version number from project properties

    3. change product version from message box displayed

    Sunday, February 17, 2019 10:38 AM