Ejemplo n.º 1
0
        /// <summary>
        /// Removes all values of a property from all projects
        /// (for a given configuration/platform)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        public void Move(string name, string val)
        {
            Parallel.ForEach(_allProjects, proj =>
            {
                ProjectProperty p = proj.GetProperty(name);
                if (p != null &&
                    !p.IsEnvironmentProperty &&
                    !p.IsGlobalProperty &&
                    !p.IsImported &&
                    !p.IsReservedProperty)
                {
                    proj.RemoveProperty(p);
                }
            });

            if (_allFoundProperties.ContainsKey(name))
            {
                ReferencedProperty refp = _allFoundProperties[name];
                refp.RemoveProjects(_allProjects);
                if (refp.UsedCount == 0)
                {
                    bool removed = _allFoundProperties.Remove(name);
                    Debug.Assert(removed, "Property was not removed from the list");
                }
            }

            UpdatePropertySheet(name, val);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes properties from all configurations in all files.
        /// It actually ignores the global configuration and global platform
        /// and operates on just the raw XML elements.
        /// </summary>
        /// <param name="propNames"></param>
        public void RemoveXml(List <string> propNames)
        {
            foreach (var name in propNames)
            {
                foreach (var project in _allProjects)
                {
                    var deleteThese         = new List <ProjectPropertyElement>();
                    var emptyGroups         = new List <ProjectPropertyGroupElement>();
                    ProjectRootElement root = project.Xml;
                    foreach (var group in root.PropertyGroups)
                    {
                        foreach (ProjectPropertyElement prop in group.Properties)
                        {
                            if (String.Compare(name, prop.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
                            {
                                deleteThese.Add(prop);
                            }
                        }
                    }

                    foreach (var prop in deleteThese)
                    {
                        prop.Parent.RemoveChild(prop);
                    }

                    foreach (var group in root.PropertyGroups)
                    {
                        if (group.Children.Count == 0)
                        {
                            // Parents have no more children. Mark them for deletion.
                            emptyGroups.Add(group);
                        }
                    }
                    foreach (var group in emptyGroups)
                    {
                        group.Parent.RemoveChild(group);
                    }
                    project.Save();
                }

                if (_allFoundProperties.ContainsKey(name))
                {
                    ReferencedProperty refp = _allFoundProperties[name];
                    refp.RemoveProjects(_allProjects);
                    if (refp.UsedCount == 0)
                    {
                        bool removed = _allFoundProperties.Remove(name);
                        Debug.Assert(removed, "Property was not removed from the list");
                    }
                }
            }
        }