Exemple #1
0
        private IEnumerable <XElement> GetItems(MsbuildFile msbuildFile, Project project, string friendlyQualifierName)
        {
            if (project.Items.Count == 0)
            {
                return(EmptyArray <XElement>());
            }

            string evaluatedQualifierComparisonValue = null;

            if (friendlyQualifierName != null)
            {
                evaluatedQualifierComparisonValue = msbuildFile.GetQualifierComparisonValue(friendlyQualifierName);
            }

            var items = project.Items.OrderBy(grouping => grouping.Key).Select(
                grouping => new XElement(
                    ItemGroupXName,
                    string.IsNullOrEmpty(evaluatedQualifierComparisonValue)
                        ? EmptyArray <XAttribute>()
                        : (object)new XAttribute("Condition", $"'{msbuildFile.UnevaluatedQualifierComparisonProperty}' == '{evaluatedQualifierComparisonValue}'"),
                    grouping
                    .Where(item => !IsExcludedItemInclude(ValueToMsBuild(item.Include, msbuildFile)))
                    .OrderBy(item => ValueToMsBuild(item.Include, msbuildFile), StringComparer.OrdinalIgnoreCase)
                    .Select(
                        item => new XElement(
                            XName.Get(grouping.Key, MsBuildNamespace),
                            new XAttribute("Include", ValueToMsBuild(item.Include, msbuildFile)),
                            item.Metadata
                            .OrderBy(kv => kv.Key)
                            .Select(kv => new XElement(XName.Get(kv.Key, MsBuildNamespace), ValueToMsBuild(kv.Value, msbuildFile)))))));

            return(items);
        }
Exemple #2
0
        private IEnumerable <XElement> GetProperties(MsbuildFile msbuildFile, Project project, string friendlyQualifierName)
        {
            string evaluatedQualifierComparisonValue = null;

            if (friendlyQualifierName != null)
            {
                evaluatedQualifierComparisonValue = msbuildFile.GetQualifierComparisonValue(friendlyQualifierName);
            }

            var properties = new XElement(
                PropertyGroupXName,
                string.IsNullOrEmpty(evaluatedQualifierComparisonValue)
                        ? EmptyArray <XAttribute>()
                        : (object)new XAttribute("Condition", $"'{msbuildFile.UnevaluatedQualifierComparisonProperty}' == '{evaluatedQualifierComparisonValue}'"),
                project.Properties.OrderBy(kv => kv.Key, StringComparer.OrdinalIgnoreCase)
                .Select(kv => new XElement(XName.Get(kv.Key, MsBuildNamespace), ValueToMsBuild(kv.Value, msbuildFile, true))));

            if (properties.HasElements)
            {
                yield return(properties);
            }
        }