void IConfigurationOrPlatformNameCollection.Rename(string oldName, string newName)
        {
            newName = ValidateName(newName);
            if (newName == null)
            {
                throw new ArgumentException();
            }

            lock (project.SyncRoot) {
                foreach (ProjectPropertyGroupElement g in project.MSBuildProjectFile.PropertyGroups.Concat(project.MSBuildUserProjectFile.PropertyGroups))
                {
                    // Rename the default configuration setting
                    ProjectPropertyElement prop = FindConfigElement(g);
                    if (prop != null && ConfigurationAndPlatform.ConfigurationNameComparer.Equals(prop.Value, oldName))
                    {
                        prop.Value = newName;
                    }

                    // Rename the configuration in conditions
                    var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                    if (HasName(gConfig, oldName))
                    {
                        g.Condition = SetName(gConfig, newName).ToCondition();
                    }
                }
                project.LoadConfigurationPlatformNamesFromMSBuild();

                AdjustMapping(oldName, newName);
            }
        }
        void IConfigurationOrPlatformNameCollection.Remove(string name)
        {
            SD.MainThread.VerifyAccess();
            lock (project.SyncRoot) {
                string otherName = null;
                foreach (string configName in this)
                {
                    if (!ConfigurationAndPlatform.ConfigurationNameComparer.Equals(configName, name))
                    {
                        otherName = configName;
                        break;
                    }
                }
                if (otherName == null)
                {
                    throw new InvalidOperationException("cannot remove the last configuration/platform");
                }
                foreach (ProjectPropertyGroupElement g in project.MSBuildProjectFile.PropertyGroups.Concat(project.MSBuildUserProjectFile.PropertyGroups).ToList())
                {
                    ProjectPropertyElement prop = FindConfigElement(g);
                    if (prop != null && ConfigurationAndPlatform.ConfigurationNameComparer.Equals(prop.Value, name))
                    {
                        prop.Value = otherName;
                    }

                    var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                    if (HasName(gConfig, name))
                    {
                        g.Parent.RemoveChild(g);
                    }
                }
                project.LoadConfigurationPlatformNamesFromMSBuild();

                AdjustMapping(name, otherName);
            }
        }
        void IConfigurationOrPlatformNameCollection.Add(string newName, string copyFrom)
        {
            SD.MainThread.VerifyAccess();
            newName = ValidateName(newName);
            if (newName == null)
            {
                throw new ArgumentException();
            }
            lock (project.SyncRoot) {
                var  projectFile           = project.MSBuildProjectFile;
                var  userProjectFile       = project.MSBuildUserProjectFile;
                bool copiedGroupInMainFile = false;
                if (copyFrom != null)
                {
                    copyFrom = MSBuildInternals.FixPlatformNameForProject(copyFrom);
                    foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.ToList())
                    {
                        var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                        if (HasName(gConfig, copyFrom))
                        {
                            CopyProperties(projectFile, g, SetName(gConfig, newName));
                            copiedGroupInMainFile = true;
                        }
                    }
                    foreach (ProjectPropertyGroupElement g in userProjectFile.PropertyGroups.ToList())
                    {
                        var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                        if (HasName(gConfig, copyFrom))
                        {
                            CopyProperties(userProjectFile, g, SetName(gConfig, newName));
                        }
                    }
                }
                if (!copiedGroupInMainFile)
                {
                    projectFile.AddPropertyGroup().Condition = (isPlatform ? new ConfigurationAndPlatform(null, newName) : new ConfigurationAndPlatform(newName, null)).ToCondition();
                }
                project.LoadConfigurationPlatformNamesFromMSBuild();

                // Adjust mapping:
                // If the new config/platform already exists in the solution and is mapped to some old project config/platform,
                // re-map it to the new config/platform.
                var mapping = project.ConfigurationMapping;
                if (isPlatform)
                {
                    string newNameForSolution = MSBuildInternals.FixPlatformNameForSolution(newName);
                    if (project.ParentSolution.PlatformNames.Contains(newNameForSolution, ConfigurationAndPlatform.ConfigurationNameComparer))
                    {
                        foreach (string solutionConfiguration in project.ParentSolution.ConfigurationNames)
                        {
                            var solutionConfig = new ConfigurationAndPlatform(solutionConfiguration, newNameForSolution);
                            var projectConfig  = mapping.GetProjectConfiguration(solutionConfig);
                            mapping.SetProjectConfiguration(solutionConfig, SetName(projectConfig, newName));
                        }
                    }
                }
                else
                {
                    if (project.ParentSolution.ConfigurationNames.Contains(newName, ConfigurationAndPlatform.ConfigurationNameComparer))
                    {
                        foreach (string solutionPlatform in project.ParentSolution.PlatformNames)
                        {
                            var solutionConfig = new ConfigurationAndPlatform(newName, solutionPlatform);
                            var projectConfig  = mapping.GetProjectConfiguration(solutionConfig);
                            mapping.SetProjectConfiguration(solutionConfig, SetName(projectConfig, newName));
                        }
                    }
                }
                project.ActiveConfiguration = mapping.GetProjectConfiguration(project.ParentSolution.ActiveConfiguration);
            }
        }