private void RemoveDefaultedProperties()
        {
            foreach (var propGroup in _projectRootElement.PropertyGroups)
            {
                var configurationName = MSBuildUtilities.GetConfigurationName(propGroup.Condition);
                var propDiff          = _differs[configurationName].GetPropertiesDiff();

                foreach (var prop in propGroup.Properties)
                {
                    // These properties were added to the baseline - so don't treat them as defaulted properties.
                    if (_sdkBaselineProject.GlobalProperties.Contains(prop.Name, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (propDiff.DefaultedProperties.Select(p => p.Name).Contains(prop.Name, StringComparer.OrdinalIgnoreCase) ||
                        Facts.PropertiesNotNeededInCPS.Contains(prop.Name, StringComparer.OrdinalIgnoreCase))
                    {
                        propGroup.RemoveChild(prop);
                    }
                }

                // If a propertyGroup is empty we can remove it unless it had a condition from which a configuration is inferred.
                if (propGroup.Properties.Count == 0 && string.IsNullOrEmpty(configurationName))
                {
                    _projectRootElement.RemoveChild(propGroup);
                }
            }
        }
Exemple #2
0
        private void RemoveDefaultedProperties()
        {
            foreach (var propGroup in _projectRootElement.PropertyGroups)
            {
                var configurationName = MSBuildUtilities.GetConfigurationName(propGroup.Condition);
                var propDiff          = _differs[configurationName].GetPropertiesDiff();

                foreach (var prop in propGroup.Properties)
                {
                    // These properties were added to the baseline - so don't treat them as defaulted proeprties.
                    if (_sdkBaselineProject.GlobalProperties.Contains(prop.Name))
                    {
                        continue;
                    }

                    if (propDiff.DefaultedProperties.Select(p => p.Name).Contains(prop.Name) ||
                        Facts.PropertiesNotNeededInCPS.Contains(prop.Name))
                    {
                        propGroup.RemoveChild(prop);
                    }
                }

                if (propGroup.Properties.Count == 0)
                {
                    _projectRootElement.RemoveChild(propGroup);
                }
            }
        }
Exemple #3
0
        private ImmutableDictionary <string, ImmutableDictionary <string, string> > DetermineConfigurations(IProjectRootElement projectRootElement)
        {
            var builder = ImmutableDictionary.CreateBuilder <string, ImmutableDictionary <string, string> >();

            foreach (var propertyGroup in projectRootElement.PropertyGroups)
            {
                if (MSBuildUtilities.ConditionToDimensionValues(propertyGroup.Condition, out var dimensionValues))
                {
                    var name = MSBuildUtilities.GetConfigurationName(dimensionValues);
                    builder.Add(name, dimensionValues.ToImmutableDictionary());
                }
            }

            return(builder.ToImmutable());
        }
        private void RemoveOrUpdateItems()
        {
            foreach (var itemGroup in _projectRootElement.ItemGroups)
            {
                var configurationName = MSBuildUtilities.GetConfigurationName(itemGroup.Condition);
                var itemsDiff         = _differs[configurationName].GetItemsDiff();

                foreach (var item in itemGroup.Items)
                {
                    ItemsDiff itemTypeDiff = itemsDiff.FirstOrDefault(id => id.ItemType.Equals(item.ItemType, StringComparison.OrdinalIgnoreCase));
                    if (!itemTypeDiff.DefaultedItems.IsDefault)
                    {
                        var defaultedItems = itemTypeDiff.DefaultedItems.Select(i => i.EvaluatedInclude);
                        if (defaultedItems.Contains(item.Include, StringComparer.OrdinalIgnoreCase))
                        {
                            itemGroup.RemoveChild(item);
                        }
                    }

                    if (!itemTypeDiff.ChangedItems.IsDefault)
                    {
                        var changedItems = itemTypeDiff.ChangedItems.Select(i => i.EvaluatedInclude);
                        if (changedItems.Contains(item.Include, StringComparer.OrdinalIgnoreCase))
                        {
                            var path = item.Include;
                            item.Include = null;
                            item.Update  = path;
                        }
                    }
                }

                if (itemGroup.Items.Count == 0)
                {
                    _projectRootElement.RemoveChild(itemGroup);
                }
            }
        }