Exemplo n.º 1
0
        /// <summary>
        /// Creates a props file to find best $(Configuration) from $(BuildConfigurations) for a specific $(BuildConfiguration)
        /// </summary>
        /// <param name="buildConfiguration"></param>
        private void CreateBuildConfigurationPropsFile(Configuration buildConfiguration)
        {
            var configurationSpecificProps     = ProjectRootElement.Create();
            var compatibleConfigurationStrings = new StringBuilder();

            // delimit BuildConfigurations for parsing
            var parseBuildConfigurationsPropertyGroup = configurationSpecificProps.AddPropertyGroup();
            var parseBuildConfigurationsName          = $"_parse_{AvailableBuildConfigurationsProperty}";
            var parseBuildConfigurationsValue         = $"{ConfigurationSeperator}$({AvailableBuildConfigurationsProperty}.Replace('%0A','').Replace('%0D','').Replace(' ','')){ConfigurationSeperator}";

            parseBuildConfigurationsPropertyGroup.AddProperty(parseBuildConfigurationsName, parseBuildConfigurationsValue);

            var chooseConfigurationElement = configurationSpecificProps.CreateChooseElement();

            configurationSpecificProps.AppendChild(chooseConfigurationElement);

            // determine compatible project configurations and select best one
            foreach (var compatibleConfiguration in ConfigurationFactory.GetCompatibleConfigurations(buildConfiguration))
            {
                var configurationStrings = compatibleConfiguration.GetSignificantConfigurationStrings();

                if (compatibleConfigurationStrings.Length > 0)
                {
                    compatibleConfigurationStrings.Append(ConfigurationSeperatorString);
                }
                compatibleConfigurationStrings.Append(string.Join(ConfigurationSeperatorString, configurationStrings));

                var guardedProjectConfigurationStrings = configurationStrings.Select(c => ConfigurationSeperator + c + ConfigurationSeperator);
                var configurationCondition             = CreateContainsCondition(parseBuildConfigurationsName, guardedProjectConfigurationStrings);
                var whenConfigurationElement           = configurationSpecificProps.CreateWhenElement(configurationCondition);
                chooseConfigurationElement.AppendChild(whenConfigurationElement);

                // add property to set Configuration
                var setConfigurationPropertyGroup = configurationSpecificProps.CreatePropertyGroupElement();
                whenConfigurationElement.AppendChild(setConfigurationPropertyGroup);

                // set project configuration
                setConfigurationPropertyGroup.AddProperty(ConfigurationProperty, compatibleConfiguration.GetDefaultConfigurationString());
            }

            var configurationOtherwiseElement = configurationSpecificProps.CreateOtherwiseElement();

            chooseConfigurationElement.AppendChild(configurationOtherwiseElement);

            var configurationOtherwisePropertyGroup = configurationSpecificProps.CreatePropertyGroupElement();

            configurationOtherwiseElement.AppendChild(configurationOtherwisePropertyGroup);

            configurationOtherwisePropertyGroup.AddProperty(ErrorMessageProperty,
                                                            $"$({ErrorMessageProperty})Could not find a compatible configuration for {BuildConfigurationProperty} '$({BuildConfigurationProperty})' " +
                                                            $"from {AvailableBuildConfigurationsProperty} '$({parseBuildConfigurationsName})'.  " +
                                                            $"Considered {compatibleConfigurationStrings}.");

            // save a copy of for each synonymous config string
            foreach (var configurationString in buildConfiguration.GetSignificantConfigurationStrings())
            {
                var configurationProjectPath = Path.Combine(PropsFolder, $"{ConfigurationPropsPrefix}.{configurationString}{PropsFileExtension}");
                configurationSpecificProps.Save(configurationProjectPath);
            }
        }
Exemplo n.º 2
0
        public override bool Execute()
        {
            LoadConfiguration();

            var supportedProjectConfigurations = new HashSet <Configuration>(
                BuildConfigurations.Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => ConfigurationFactory.ParseConfiguration(c)),
                Configuration.CompatibleComparer);

            var buildConfiguration = ConfigurationFactory.ParseConfiguration(BuildConfiguration);

            var compatibleConfigurations = ConfigurationFactory.GetCompatibleConfigurations(buildConfiguration, DoNotAllowCompatibleValues);

            var bestConfiguration = compatibleConfigurations.FirstOrDefault(c => supportedProjectConfigurations.Contains(c));

            if (bestConfiguration == null)
            {
                Log.LogMessage($"Could not find any applicable configuration for '{buildConfiguration}' among projectConfigurations {string.Join(", ", supportedProjectConfigurations.Select(c => c.ToString()))}");
                Log.LogMessage(MessageImportance.Low, $"Compatible configurations: {string.Join(", ", compatibleConfigurations.Select(c => c.ToString()))}");
            }
            else
            {
                Log.LogMessage(MessageImportance.Low, $"Chose configuration {bestConfiguration}");
                BestConfiguration = new TaskItem(bestConfiguration.ToString(), (IDictionary)bestConfiguration.GetProperties());
            }

            return(!Log.HasLoggedErrors);
        }
        public override bool Execute()
        {
            LoadConfiguration();

            Dictionary <Configuration, Configuration> supportedProjectConfigurations = SupportedConfigurations.Where(c => !string.IsNullOrWhiteSpace(c))
                                                                                       .Distinct(StringComparer.OrdinalIgnoreCase)
                                                                                       .Select(c => ConfigurationFactory.ParseConfiguration(c))
                                                                                       .ToDictionary(c => c, Configuration.CompatibleComparer);

            var bestConfigurations = new List <ITaskItem>();

            foreach (var configurationItem in Configurations)
            {
                var buildConfiguration = ConfigurationFactory.ParseConfiguration(configurationItem.ItemSpec);

                var compatibleConfigurations = ConfigurationFactory.GetCompatibleConfigurations(buildConfiguration, DoNotAllowCompatibleValues);

                Configuration supportedProjectConfiguration = null;

                var bestConfiguration = compatibleConfigurations.FirstOrDefault(c => supportedProjectConfigurations.TryGetValue(c, out supportedProjectConfiguration));

                if (bestConfiguration == null)
                {
                    Log.LogMessage(MessageImportance.Low, $"Could not find any applicable configuration for '{buildConfiguration}' among projectConfigurations {string.Join(", ", supportedProjectConfigurations.Select(c => c.ToString()))}");
                    Log.LogMessage(MessageImportance.Low, $"Compatible configurations: {string.Join(", ", compatibleConfigurations.Select(c => c.ToString()))}");
                }
                else
                {
                    if (supportedProjectConfiguration.IsPlaceHolderConfiguration)
                    {
                        Log.LogMessage($"Skipped configuration: {supportedProjectConfiguration.ToString()} because was marked as a placeholder configuration");
                        continue;
                    }

                    Log.LogMessage(MessageImportance.Low, $"Chose configuration {bestConfiguration}");
                    var bestConfigurationItem = new TaskItem(bestConfiguration.ToString(), (IDictionary)bestConfiguration.GetProperties());

                    // preserve metadata on the configuration that selected this
                    configurationItem.CopyMetadataTo(bestConfigurationItem);

                    // preserve the configuration that selected this
                    bestConfigurationItem.SetMetadata("BuildConfiguration", configurationItem.ItemSpec);
                    foreach (var additionalProperty in buildConfiguration.GetProperties())
                    {
                        bestConfigurationItem.SetMetadata("BuildConfiguration_" + additionalProperty.Key, additionalProperty.Value);
                    }

                    bestConfigurations.Add(bestConfigurationItem);
                }
            }

            BestConfigurations = bestConfigurations.ToArray();

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 4
0
        public override bool Execute()
        {
            LoadConfiguration();

            var supportedProjectConfigurations = new HashSet <Configuration>(
                SupportedConfigurations.Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => ConfigurationFactory.ParseConfiguration(c)),
                Configuration.CompatibleComparer);

            var ignoredBuildConfigurations = new HashSet <string>(SupportedConfigurations.Where(c => c.StartsWith(ConfigurationFactory.NopConfigurationPrefix)));

            var bestConfigurations = new List <ITaskItem>();

            foreach (var configurationItem in Configurations)
            {
                var buildConfiguration = ConfigurationFactory.ParseConfiguration(configurationItem.ItemSpec);

                var compatibleConfigurations = ConfigurationFactory.GetCompatibleConfigurations(buildConfiguration, DoNotAllowCompatibleValues);

                var bestConfiguration = compatibleConfigurations.FirstOrDefault(c => supportedProjectConfigurations.Contains(c));

                if (bestConfiguration == null)
                {
                    Log.LogMessage(MessageImportance.Low, $"Could not find any applicable configuration for '{buildConfiguration}' among projectConfigurations {string.Join(", ", supportedProjectConfigurations.Select(c => c.ToString()))}");
                    Log.LogMessage(MessageImportance.Low, $"Compatible configurations: {string.Join(", ", compatibleConfigurations.Select(c => c.ToString()))}");
                }
                else
                {
                    if (ignoredBuildConfigurations.Contains($"{ConfigurationFactory.NopConfigurationPrefix}{bestConfiguration}"))
                    {
                        BestConfigurations = Array.Empty <ITaskItem>();
                        return(!Log.HasLoggedErrors);
                    }

                    Log.LogMessage(MessageImportance.Low, $"Chose configuration {bestConfiguration}");
                    var bestConfigurationItem = new TaskItem(bestConfiguration.ToString(), (IDictionary)bestConfiguration.GetProperties());

                    // preserve metadata on the configuration that selected this
                    configurationItem.CopyMetadataTo(bestConfigurationItem);

                    // preserve the configuration that selected this
                    bestConfigurationItem.SetMetadata("BuildConfiguration", configurationItem.ItemSpec);
                    foreach (var additionalProperty in buildConfiguration.GetProperties())
                    {
                        bestConfigurationItem.SetMetadata("BuildConfiguration_" + additionalProperty.Key, additionalProperty.Value);
                    }

                    bestConfigurations.Add(bestConfigurationItem);
                }
            }

            BestConfigurations = bestConfigurations.ToArray();

            return(!Log.HasLoggedErrors);
        }