Files are removed from the application folder after upgrading a Setup project from Visual Studio 2008 to Visual Studio 2010

If you migrate a Setup project from Visual Studio 2008 to Visual Studio 2010 and set the property RemovePreviousVersion=True, The upgrade package removes the application folder once it is installed.

This issue occurs because the Component GUID's are changed when setup projects are migrated from Visual Studio 2008 to Visual Studio 2010. InstallValidate Action marks components to be installed locally, RemoveExistingProducts that runs at sequence 6550 ends up removing those components.

There are two solutions:

1. Manually change the component GUID's to be the same as that of VS2008

2. Re-sequence the RemoveExistingProducts Action right after InstallInitialize (sequence number 1500+). This ensures that older files are removed and reinstalled by the newer version.

The second solution can be achieved by running a post build script OR manually editing the MSI package using Orca.exe(It comes with Windows SDK).

You can add the below text into a file next to your .vdproj called "fix.js", and then set your "PostBuildEvent" property to exactly the following string, to run it after every build - cscript.exe "$(ProjectDir)\fix.js" "$(BuiltOuputPath)"


//fix.js File

var newSequence = 1501;

var msiOpenDatabaseModeTransact = 1;

var msiViewModifyReplace = 4

if (WScript.Arguments.Length != 1)
    WScript.StdErr.WriteLine(WScript.ScriptName + " file");

var filespec = WScript.Arguments(0);
var installer = WScript.CreateObject("WindowsInstaller.Installer");
var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);

var sql
var view
var record

    WScript.Echo("Updating the InstallExecuteSequence table...");

    sql = "SELECT `Action`, `Sequence` FROM `InstallExecuteSequence` WHERE `Action`='RemoveExistingProducts'";
    view = database.OpenView(sql);
    record = view.Fetch();
        if (record.IntegerData(2) == newSequence)
        throw "REP sequence doesn't match expected value - this database appears to have been already modified by this script!";
        if (record.IntegerData(2) != 6550)
        throw "REP sequence doesn't match expected value - this database was either already modified by something else after build, or was not produced by Visual Studio 2010!";
    record.IntegerData(2) = newSequence;
    view.Modify(msiViewModifyReplace, record);


Comments (6)

  1. Prasoon says:

    Is the "issue" really a bug on the side of Visual Studio 2010? If so, are they planning out an update/hot fix for this issue? If not, then why?

  2. Prasoon says:

    It's again me.. 🙂 I check the component's GUID in the MSI using Orca; I have noticed that they are indeed different. Anyways, one of the suggested method included changing the Component's ID back to be same as the older versions. How can we go about doing that?


    Answer: In order to change the Component's ID, you need to open both the MSI packages in Orca and copy/paste the ID from one package to another package.

    Alternatively, you may follow the second method as mentioned in the blog. Moreover, Visual Studio Setup projects would be deprecated in the next release of Visual Studio.

    -Soumitra Mondal



  3. Kasper says:


    this fix.js worked great for getting the files to install, instead of getting deleted. But now my files don't get registered for com interop.

  4. Wasim says:

    hi all, i have VS2010, and i created deployment project to generate msi, and everything goes well, but sometime when i run the msi on any client pc it didn't remove the previous version even i set removepreviouspervios property to true, specifically when i updated the config file on pc manulay,..

    any advice,,, thnx in advance

  5. You can share the verbose log for the upgrade package.

  6. GSP_T says:

    Kasper, did you ever get your problem resolved?

Skip to main content