示例#1
0
        public static IEnumerable <KeyValueSetting> GetXmlProjectSettings(
            this IProjectFolder project,
            string settingsTagName,
            string settingsKeyAttribute,
            string settingsValueAttributes)
        {
            var result = new Dictionary <string, HashSet <string> >();

            var configFiles = GetXmlConfigFiles(project);

            foreach (var configFile in configFiles)
            {
                var settingsTags = new Queue <IXmlTag>(GetSettingTags(settingsTagName, configFile));
                while (settingsTags.Count > 0)
                {
                    var settingTag = settingsTags.Dequeue();

                    var configName = settingTag.GetExternalConfigName();
                    if (!string.IsNullOrEmpty(configName))
                    {
                        var projectItems =
                            project.FindProjectItemsByLocation(configFile.Location.Directory.Combine(configName));
                        foreach (var projectItem in projectItems)
                        {
                            var projectFile          = projectItem as IProjectFile;
                            var externalSettingsTags = GetSettingTags(settingsTagName, projectFile);
                            foreach (var settingsTag in externalSettingsTags)
                            {
                                settingsTags.Enqueue(settingsTag);
                            }
                        }

                        continue;
                    }

                    var settings = settingTag.GetChildSettings(settingsKeyAttribute, settingsValueAttributes);
                    foreach (var setting in settings)
                    {
                        if (!result.TryGetValue(setting.Key, out var settingValues))
                        {
                            settingValues = new HashSet <string>();
                            result.Add(setting.Key, settingValues);
                        }

                        settingValues.Add(setting.Value);
                    }
                }
            }

            return(result.Select(x => new KeyValueSetting(x.Key, string.Join(", ", x.Value))));
        }
示例#2
0
        public static IEnumerable <KeyValueSetting> GetXmlProjectSettings(
            this IProjectFolder project,
            string settingsTagName,
            string settingsKeyAttribute,
            string settingsValueAttributes)
        {
            var result = new HashSet <KeyValueSetting>(KeyValueSetting.KeyComparer);

            var configFiles = GetXmlConfigFiles(project);

            foreach (var configFile in configFiles)
            {
                var settingsTags = new Queue <IXmlTag>(GetSettingTags(settingsTagName, configFile));
                while (settingsTags.Count > 0)
                {
                    var settingTag = settingsTags.Dequeue();

                    var configName = settingTag.GetExternalConfigName();
                    if (!string.IsNullOrEmpty(configName))
                    {
                        var projectItems =
                            project.FindProjectItemsByLocation(configFile.Location.Directory.Combine(configName));
                        foreach (var projectItem in projectItems)
                        {
                            var projectFile          = projectItem as IProjectFile;
                            var externalSettingsTags = GetSettingTags(settingsTagName, projectFile);
                            foreach (var settingsTag in externalSettingsTags)
                            {
                                settingsTags.Enqueue(settingsTag);
                            }
                        }

                        continue;
                    }

                    var settings = settingTag.GetChildSettings(settingsKeyAttribute, settingsValueAttributes);
                    NuGet.CollectionExtensions.AddRange(result, settings);
                }
            }

            return(result);
        }