private void AddOutputPath(Microsoft.Build.Construction.ProjectPropertyGroupElement newConfig, string configName)
        {
            //add the output path
            string outputBasePath = this.ProjectMgr.OutputBaseRelativePath;

            if (outputBasePath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            {
                outputBasePath = Path.GetDirectoryName(outputBasePath);
            }
            newConfig.AddProperty("OutputPath", Path.Combine(outputBasePath, configName) + Path.DirectorySeparatorChar.ToString());
        }
        private void PopulateEmptyConfig(ref Microsoft.Build.Construction.ProjectPropertyGroupElement newConfig)
        {
            newConfig = this.project.BuildProject.Xml.AddPropertyGroup();
            // Get the list of property name, condition value from the config provider
            IList <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;
                Microsoft.Build.Construction.ProjectPropertyElement newProperty = newConfig.AddProperty(propData.Key, value);
                if (!String.IsNullOrEmpty(propData.Value))
                {
                    newProperty.Condition = propData.Value;
                }
            }
        }
        /// <summary>
        /// Copies an existing platform name or creates a new one.
        /// </summary>
        /// <param name="platformName">The name of the new platform.</param>
        /// <param name="clonePlatformName">The name of the platform to copy, or a null reference, indicating that AddCfgsOfPlatformName should create a new platform.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int AddCfgsOfPlatformName(string platformName, string clonePlatformName)
        {
            // We need to QE/QS the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Get all configs
            this.project.BuildProject.ReevaluateIfNecessary();
            List <Microsoft.Build.Construction.ProjectPropertyGroupElement> configGroup = new List <Microsoft.Build.Construction.ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups);
            // configName -> property group
            var configToClone = new Dictionary <string, Microsoft.Build.Construction.ProjectPropertyGroupElement>(StringComparer.Ordinal);


            if (clonePlatformName != null)
            {
                // Find the configuration to clone
                foreach (var currentConfig in configGroup)
                {
                    // Only care about conditional property groups
                    if (currentConfig.Condition == null || currentConfig.Condition.Length == 0)
                    {
                        continue;
                    }
                    var configCanonicalName = ConfigCanonicalName.OfCondition(currentConfig.Condition);

                    // Skip if it isn't the group we want
                    if (!configCanonicalName.MatchesPlatform(clonePlatformName))
                    {
                        continue;
                    }

                    if (!configToClone.ContainsKey(configCanonicalName.ConfigName))
                    {
                        configToClone.Add(configCanonicalName.ConfigName, currentConfig);
                    }
                }
            }


            var configNames = GetPropertiesConditionedOn(ProjectFileConstants.Configuration);

            if (configNames.Length == 0)
            {
                return(VSConstants.E_FAIL);
            }

            foreach (var configName in configNames)
            {
                // If we have any property groups to clone, and we do not have sourec for this config, skip
                if (configToClone.Count > 0 && !configToClone.ContainsKey(configName))
                {
                    continue;
                }
                var newCanonicalName = new ConfigCanonicalName(configName, platformName);

                Microsoft.Build.Construction.ProjectPropertyGroupElement newConfig = null;
                if (configToClone.ContainsKey(configName))
                {
                    // Clone the configuration settings
                    newConfig = this.project.ClonePropertyGroup(configToClone[configName]);
                    foreach (Microsoft.Build.Construction.ProjectPropertyElement property in newConfig.Properties)
                    {
                        if (property.Name.Equals(ProjectFileConstants.PlatformTarget, StringComparison.OrdinalIgnoreCase))
                        {
                            property.Parent.RemoveChild(property);
                        }
                    }
                }
                else
                {
                    // no source to clone from, lets just create a new empty config
                    PopulateEmptyConfig(ref newConfig);
                    this.AddOutputPath(newConfig, configName);
                }

                newConfig.AddProperty(ProjectFileConstants.PlatformTarget, newCanonicalName.PlatformTarget);

                // Set the condition that will define the new configuration
                string newCondition = newCanonicalName.ToMSBuildCondition();
                newConfig.Condition = newCondition;
            }
            NotifyOnPlatformNameAdded(platformName);
            return(VSConstants.S_OK);
        }