how to stop loading the upgrade when project fails RRS feed

  • Question

  • Hi,

    I have a project file of my own and I have implemented IVSProjectUpgradeViaFactory on my ProjectFactory. I am using MPF2010. Now I want to modify the project file when the upgrade is happening. Basically I was using a different XML format for my project file earlier and now I have changed it to the one used by MSBuild. So my project upgrade needs the older XML format to be converted to the format used by MSBuild. The problem I am facing is that, when the project file is READOnly, I cannot change the older XML and I am returning VSConstans.VS_E_PROJECTMIGRATIONFAILED. But still it completes the upgrade and says it to be SUCCESSFUL and also shows the project in solution explorer (UNLOADED). When I try to reload it, it says the project file in not in the format used by MSBuild. 


    So my query is, is there a way I can stop the VS project upgrade and inform the user to make the file writable before proceeding further in Project Upgrade? Can I somehow stop the upgrade through C#.

    Following is my UpgradeProject_CheckOnly() implementation



    static bool ProjectMigrationFailed;

    int IVsProjectUpgradeViaFactory.UpgradeProject_CheckOnly(string bstrFileName, IVsUpgradeLogger pLogger,

         out int pUpgradeRequired, out Guid pguidNewProjectFactory, out uint pUpgradeProjectCapabilityFlags)



          pUpgradeRequired = VSConstants.S_OK;

          pUpgradeProjectCapabilityFlags = uint.MaxValue;

          pguidNewProjectFactory = Guid.Empty;


          if (ProjectMigrationFailed)


            return VSConstants.VS_E_PROJECTMIGRATIONFAILED;



          bool upgradeNeeded;


          if (upgradeNeeded)


            pUpgradeRequired = Convert.ToInt32(true);



            string bstrProjName = bstrFileName.Substring(bstrFileName.LastIndexOf('\\') + 1);

            int hr = CheckIfEditIsAllowedOnProject(bstrFileName, pLogger);

            if (hr != VSConstants.S_OK)

              return hr;


            int errorCode;

            if (!LoadAndConvertProjectFileUsingMSBuild(bstrFileName, out errorCode))


              ProjectMigrationFailed = true;

              return VSConstants.VS_E_PROJECTMIGRATIONFAILED;


            ProjectMigrationFailed = false;

          return VSConstants.S_OK;



    Prasad Gawde
    Thursday, July 21, 2011 6:36 AM

All replies

  • Hello

    The new project upgrade architecture requires two calls: the first to check the project to see if an upgrade is necessary; the second to perform the upgrade. In some cases, this requires the factory to open the project file twice.


    Therefore, we can exam the file to see if the file is writable. We can use System.IO.Fileinfo to load a file to check if the “Read Only” is the FileAttribute for the file.  E.g.


    FileInfo fi = new System.IO.FileInfo(@"C:\abc.txt");

    if (System.IO.FileAttributes.ReadOnly == fi.Attributes)


    //The file is read only, return an error code.


    We can return an error code in UpgradeProject_CheckOnly, and skip the afterward UpgradeProject calls.


    If I misunderstand you, please let me know.



    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 25, 2011 8:25 AM
  • Hi Yi,


    Thanks for responding. The problem here is not in checking whether the file is writable or not. The issue is I am not able to stop the upgrade process. Even if I send VS_E_ProjectMigrationFialed, the upgrade proceeds and says the conversion complete with errors. Rather I would like Visual Studio to say that upgrade has failed. How can I do that?

    Prasad Gawde
    Monday, July 25, 2011 12:31 PM