Microsoft.VisualStudio.Project.NestedProjectNode.RenameNestedProjectInParentProject C# (CSharp) Method

RenameNestedProjectInParentProject() protected method

Renames the project file in the parent project structure.
protected RenameNestedProjectInParentProject ( string label ) : void
label string The new label.
return void
        protected virtual void RenameNestedProjectInParentProject(string label)
        {
            string existingLabel = this.Caption;

            if (String.Equals(existingLabel, label, StringComparison.Ordinal))
            {
                return;
            }

            string oldFileName = this.ProjectPath;
            string oldPath = this.Url;

            try
            {
                this.StopObservingNestedProjectFile();
                this.ProjectManager.SuspendMSBuild();

                // Check out the project file if necessary.
                if (!this.ProjectManager.QueryEditProjectFile(false))
                {
                    throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                }

                string newFileName = label + Path.GetExtension(oldFileName);
                this.SaveNestedProjectItemInProjectFile(newFileName);

                string projectDirectory = Path.GetDirectoryName(oldFileName);

                // update state.
                this._projectName = newFileName;
                this.ProjectPath = Path.Combine(projectDirectory, this._projectName);

                // Unload and lock the RDT entries
                this.UnlockRdtEntry();
                this.LockRdtEntry();

                // Since actually this is a rename in our hierarchy notify the tracker that a rename has happened.
                this.ProjectManager.Tracker.OnItemRenamed(oldPath, this.ProjectPath, VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_IsNestedProjectFile);
            }
            finally
            {
                this.ObserveNestedProjectFile();
                this.ProjectManager.ResumeMSBuild(this.ProjectManager.ReevaluateProjectFileTargetName);
            }
        }