Esempio n. 1
0
        /// <summary>
        /// Performs in-memory conversion of the project with a given path
        /// </summary>
        /// <returns>Root element of the converted project or <c>null</c> if conversion failed.</returns>
        private ProjectRootElement ConvertProject(string projectFileName, ProjectUpgradeLogger logger)
        {
            var projectConverter = new Microsoft.Build.Conversion.ProjectFileConverter();

            projectConverter.OldProjectFile = projectFileName;
            projectConverter.NewProjectFile = projectFileName;
            ProjectRootElement convertedProject = null;

            try
            {
                convertedProject = projectConverter.ConvertInMemory();
            }
            catch (Exception ex)
            {
                logger.LogInfo(ex.Message);
            }
            return(convertedProject);
        }
 /// <summary>
 /// Performs in-memory conversion of the project with a given path
 /// </summary>
 /// <returns>Root element of the converted project or <c>null</c> if conversion failed.</returns>
 private ProjectRootElement ConvertProject(string projectFileName, ProjectUpgradeLogger logger)
 {
     var projectConverter = new Microsoft.Build.Conversion.ProjectFileConverter();
     projectConverter.OldProjectFile = projectFileName;
     projectConverter.NewProjectFile = projectFileName;
     ProjectRootElement convertedProject = null;
     try
     {
         convertedProject = projectConverter.ConvertInMemory();
     }
     catch (Exception ex)
     {
         logger.LogInfo(ex.Message);
     }
     return convertedProject;
 }
        public virtual int UpgradeProject(string projectFileName, uint upgradeFlag, string copyLocation, out string upgradeFullyQualifiedFileName, IVsUpgradeLogger logger, out int upgradeRequired,
                                          out Guid newProjectFactory)
        {
            uint ignore;

            this.UpgradeProject_CheckOnly(projectFileName, logger, out upgradeRequired, out newProjectFactory, out ignore);
            if (upgradeRequired == 0)
            {
                upgradeFullyQualifiedFileName = projectFileName;
                return(VSConstants.S_OK);
            }

            string projectName = Path.GetFileNameWithoutExtension(projectFileName);

            upgradeFullyQualifiedFileName = projectFileName;

            // Query for edit
            IVsQueryEditQuerySave2 queryEdit = site.GetService(typeof(SVsQueryEditQuerySave)) as IVsQueryEditQuerySave2;

            if (queryEdit != null)
            {
                uint editVerdict;
                uint queryEditMoreInfo;
                const tagVSQueryEditFlags tagVSQueryEditFlags_QEF_AllowUnopenedProjects = (tagVSQueryEditFlags)0x80;

                int hr = queryEdit.QueryEditFiles(
                    (uint)(tagVSQueryEditFlags.QEF_ForceEdit_NoPrompting | tagVSQueryEditFlags.QEF_DisallowInMemoryEdits | tagVSQueryEditFlags_QEF_AllowUnopenedProjects),
                    1, new[] { projectFileName }, null, null, out editVerdict, out queryEditMoreInfo);
                if (ErrorHandler.Failed(hr))
                {
                    return(VSConstants.E_FAIL);
                }

                if (editVerdict != (uint)tagVSQueryEditResult.QER_EditOK)
                {
                    if (logger != null)
                    {
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, projectFileName,
                                          SR.GetString(SR.UpgradeCannotOpenProjectFileForEdit));
                    }
                    return(VSConstants.E_FAIL);
                }

                // If file was modified during the checkout, maybe upgrade is not needed
                if ((queryEditMoreInfo & (uint)tagVSQueryEditResultFlags.QER_MaybeChanged) != 0)
                {
                    this.UpgradeProject_CheckOnly(projectFileName, logger, out upgradeRequired, out newProjectFactory, out ignore);
                    if (upgradeRequired == 0)
                    {
                        if (logger != null)
                        {
                            logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, projectFileName,
                                              SR.GetString(SR.UpgradeNoNeedToUpgradeAfterCheckout));
                        }

                        return(VSConstants.S_OK);
                    }
                }
            }

            // Convert the project
            Microsoft.Build.Conversion.ProjectFileConverter projectConverter = new Microsoft.Build.Conversion.ProjectFileConverter();
            projectConverter.OldProjectFile = projectFileName;
            projectConverter.NewProjectFile = projectFileName;
            ProjectRootElement convertedProject = null;

            try
            {
                convertedProject = projectConverter.ConvertInMemory();
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, projectFileName, ex.Message);
                }
            }

            if (convertedProject != null)
            {
                this.m_lastUpgradedProjectFile = projectFileName;
                foreach (ProjectPropertyElement property in convertedProject.Properties)
                {
                    switch (property.Name)
                    {
                    case SCC_LOCAL_PATH:
                        this.m_sccLocalPath = property.Value;
                        break;

                    case SCC_AUX_PATH:
                        this.m_sccAuxPath = property.Value;
                        break;

                    case SCC_PROVIDER:
                        this.m_sccProvider = property.Value;
                        break;

                    case SCC_PROJECT_NAME:
                        this.m_sccProjectName = property.Value;
                        break;

                    default:
                        break;
                    }
                }
                try
                {
                    convertedProject.Save(projectFileName);
                }
                catch (Exception ex)
                {
                    if (logger != null)
                    {
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, projectFileName, ex.Message);
                    }
                    return(VSConstants.E_FAIL);
                }
                if (logger != null)
                {
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_STATUSMSG, projectName, projectFileName,
                                      SR.GetString(SR.UpgradeSuccessful));
                }
                return(VSConstants.S_OK);
            }

            this.m_lastUpgradedProjectFile = null;
            upgradeFullyQualifiedFileName  = "";
            return(VSConstants.E_FAIL);
        }
        public virtual int UpgradeProject(string projectFileName, uint upgradeFlag, string copyLocation, out string upgradeFullyQualifiedFileName, IVsUpgradeLogger logger, out int upgradeRequired,
                                                out Guid newProjectFactory)
        {
            uint ignore;

            this.UpgradeProject_CheckOnly(projectFileName, logger, out upgradeRequired, out newProjectFactory, out ignore);
            if (upgradeRequired == 0)
            {
                upgradeFullyQualifiedFileName = projectFileName;
                return VSConstants.S_OK;
            }

            string projectName = Path.GetFileNameWithoutExtension(projectFileName);
            upgradeFullyQualifiedFileName = projectFileName;

            // Query for edit
            IVsQueryEditQuerySave2 queryEdit = site.GetService(typeof(SVsQueryEditQuerySave)) as IVsQueryEditQuerySave2;

            if (queryEdit != null)
            {
                uint editVerdict;
                uint queryEditMoreInfo;
                const tagVSQueryEditFlags tagVSQueryEditFlags_QEF_AllowUnopenedProjects = (tagVSQueryEditFlags)0x80;

                int hr = queryEdit.QueryEditFiles(
                    (uint)(tagVSQueryEditFlags.QEF_ForceEdit_NoPrompting | tagVSQueryEditFlags.QEF_DisallowInMemoryEdits | tagVSQueryEditFlags_QEF_AllowUnopenedProjects),
                    1, new[] { projectFileName }, null, null, out editVerdict, out queryEditMoreInfo);
                if (ErrorHandler.Failed(hr))
                {
                    return VSConstants.E_FAIL;
                }

                if (editVerdict != (uint)tagVSQueryEditResult.QER_EditOK)
                {
                    if (logger != null)
                    {
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, projectFileName,
                            SR.GetString(SR.UpgradeCannotOpenProjectFileForEdit));
                    }
                    return VSConstants.E_FAIL;
                }

                // If file was modified during the checkout, maybe upgrade is not needed
                if ((queryEditMoreInfo & (uint)tagVSQueryEditResultFlags.QER_MaybeChanged) != 0)
                {
                    this.UpgradeProject_CheckOnly(projectFileName, logger, out upgradeRequired, out newProjectFactory, out ignore);
                    if (upgradeRequired == 0)
                    {
                        if (logger != null)
                        {
                            logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, projectFileName,
                                SR.GetString(SR.UpgradeNoNeedToUpgradeAfterCheckout));
                        }

                        return VSConstants.S_OK;
                    }
                }
            }

            // Convert the project
            Microsoft.Build.Conversion.ProjectFileConverter projectConverter = new Microsoft.Build.Conversion.ProjectFileConverter();
            projectConverter.OldProjectFile = projectFileName;
            projectConverter.NewProjectFile = projectFileName;
            ProjectRootElement convertedProject = null;
            try
            {
                convertedProject = projectConverter.ConvertInMemory();
            }
            catch (Exception ex)
            {
                if (logger != null)
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, projectFileName, ex.Message);
            }

            if (convertedProject != null)
            {
                this.m_lastUpgradedProjectFile = projectFileName;
                foreach (ProjectPropertyElement property in convertedProject.Properties)
                {
                    switch (property.Name)
                    {
                        case SCC_LOCAL_PATH:
                            this.m_sccLocalPath = property.Value;
                            break;
                        case SCC_AUX_PATH:
                            this.m_sccAuxPath = property.Value;
                            break;
                        case SCC_PROVIDER:
                            this.m_sccProvider = property.Value;
                            break;
                        case SCC_PROJECT_NAME:
                            this.m_sccProjectName = property.Value;
                            break;
                        default:
                            break;
                    }
                }
                try
                {
                    convertedProject.Save(projectFileName);
                }
                catch (Exception ex)
                {
                    if (logger != null)
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, projectFileName, ex.Message);
                    return VSConstants.E_FAIL;
                }
                if (logger != null)
                {
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_STATUSMSG, projectName, projectFileName,
                        SR.GetString(SR.UpgradeSuccessful));
                }
                return VSConstants.S_OK;

            }

            this.m_lastUpgradedProjectFile = null;
            upgradeFullyQualifiedFileName = "";
            return VSConstants.E_FAIL;
        }