Microsoft.VisualStudio.Project.ConfigProvider.AddPlatform C# (CSharp) Method

AddPlatform() protected method

protected AddPlatform ( Microsoft.Build.Evaluation project, string platformName ) : int
project Microsoft.Build.Evaluation
platformName string
return int
        protected virtual int AddPlatform(MSBuild.Project project, string platformName)
        {
            if (project == null)
                throw new ArgumentNullException("project");
            if (platformName == null)
                throw new ArgumentNullException("platformName");
            if (string.IsNullOrEmpty(platformName))
                throw new ArgumentException("platformName cannot be null or empty");

            MSBuildConstruction.ProjectElement lastRelevantElement = null;
            foreach (ProjectPropertyGroupElement group in project.Xml.PropertyGroupsReversed)
            {
                if (string.IsNullOrEmpty(group.Condition))
                    continue;

                if (group.Condition.IndexOf("'$(Configuration)'", StringComparison.OrdinalIgnoreCase) >= 0
                    || group.Condition.IndexOf("'$(Platform)'", StringComparison.OrdinalIgnoreCase) >= 0
                    || group.Condition.IndexOf("'$(Configuration)|$(Platform)'", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    lastRelevantElement = group;
                    break;
                }
            }

            if (lastRelevantElement == null)
                lastRelevantElement = project.Xml.PropertyGroupsReversed.First();

            string[] configurationNames = GetPropertiesConditionedOn(ProjectFileConstants.Configuration);
            foreach (var configurationName in configurationNames)
            {
                ProjectPropertyGroupElement element = project.Xml.CreatePropertyGroupElement();
                project.Xml.InsertAfterChild(element, lastRelevantElement);
                lastRelevantElement = element;

                element.Condition = GetConfigurationPlatformCondition(configurationName, platformName);

                /* TODO:
                 *  1. No need to create a property group if there are no properties to insert into in *and* this is a user build project.
                 *     If this is the main project, we still need to insert the group because the conditions are used to determine which
                 *     configurations/platforms are included in the project. For now, it's fine to always add the group.
                 *  2. Need a way to specify NewConfigProperties for each type of build project (main, user, etc).
                 */

                if (project == this._project.BuildProject)
                {
                    // Get the list of property name, condition value from the config provider
                    IEnumerable<KeyValuePair<KeyValuePair<string, string>, string>> propVals = this.NewConfigProperties;
                    foreach (KeyValuePair<KeyValuePair<string, string>, string> data in propVals)
                    {
                        KeyValuePair<string, string> propData = data.Key;
                        string value = data.Value;
                        ProjectPropertyElement newProperty = element.AddProperty(propData.Key, value);
                        if (!string.IsNullOrEmpty(propData.Value))
                            newProperty.Condition = propData.Value;
                    }

                    //add the output path
                    element.AddProperty("OutputPath", GetDefaultOutputPath(configurationName, platformName));
                }
            }

            return VSConstants.S_OK;
        }

Same methods

ConfigProvider::AddPlatform ( Microsoft.Build.Evaluation project, string platformName, string clonePlatformName ) : int