Microsoft.VisualStudio.Project.ConfigProvider.ClonePropertyGroup C# (CSharp) Method

ClonePropertyGroup() protected method

For internal use only. This creates a copy of an existing configuration and add it to the project. Caller should change the condition on the PropertyGroup. If derived class want to accomplish this, they should call ConfigProvider.AddCfgsOfCfgName() It is expected that in the future MSBuild will have support for this so we don't have to do it manually.
protected ClonePropertyGroup ( Microsoft.Build.Evaluation project, Microsoft.Build.Construction.ProjectPropertyGroupElement group ) : Microsoft.Build.Construction.ProjectPropertyGroupElement
project Microsoft.Build.Evaluation
group Microsoft.Build.Construction.ProjectPropertyGroupElement PropertyGroup to clone
return Microsoft.Build.Construction.ProjectPropertyGroupElement
        protected virtual ProjectPropertyGroupElement ClonePropertyGroup(MSBuild.Project project, ProjectPropertyGroupElement group)
        {
            if (project == null)
                throw new ArgumentNullException("project");
            if (group == null)
                throw new ArgumentNullException("group");

            // Create a new (empty) PropertyGroup
            ProjectPropertyGroupElement newPropertyGroup = project.Xml.CreatePropertyGroupElement();
            project.Xml.InsertAfterChild(newPropertyGroup, group);

            // Now copy everything from the group we are trying to clone to the group we are creating
            if (!String.IsNullOrEmpty(group.Condition))
                newPropertyGroup.Condition = group.Condition;

            foreach (ProjectPropertyElement prop in group.Properties)
            {
                ProjectPropertyElement newProperty = newPropertyGroup.AddProperty(prop.Name, prop.Value);
                if (!String.IsNullOrEmpty(prop.Condition))
                    newProperty.Condition = prop.Condition;
            }

            return newPropertyGroup;
        }