/// <summary> /// Deletes a specified platform name. /// </summary> /// <param name="platName">The platform name to delet.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> public virtual int DeleteCfgsOfPlatformName(string platName) { if (!this.ProjectMgr.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } var platform = ProjectConfig.ToMSBuildPlatform(platName); if (platform != null) { ProjectMgr.BuildProject.ReevaluateIfNecessary(); var inputElements = new List <ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups); var elementsToRemove = new List <ProjectPropertyGroupElement>(); foreach (ProjectPropertyGroupElement element in inputElements) { var cfgNameAndPlatform = ProjectConfig.ConfigAndPlatformOfCondition(element.Condition); if (ProjectConfig.EqPlatform(cfgNameAndPlatform.Item2, platform)) { elementsToRemove.Add(element); this.configurationsList.Remove(ProjectConfig.MakeConfigKey(cfgNameAndPlatform.Item1, cfgNameAndPlatform.Item2)); } } foreach (ProjectPropertyGroupElement element2 in elementsToRemove) { element2.Parent.RemoveChild(element2); } NotifyOnPlatformNameDeleted(platform); } return(VSConstants.S_OK); }
/// <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) { var msbuildPlatform = ProjectConfig.ToMSBuildPlatform(platformName); clonePlatformName = ProjectConfig.ToMSBuildPlatform(clonePlatformName); if (!this.ProjectMgr.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); //0x8004000c } ProjectMgr.BuildProject.ReevaluateIfNecessary(); var propertyGroups = new List <ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups); var dictionary = new Dictionary <string, ProjectPropertyGroupElement>(StringComparer.Ordinal); if (clonePlatformName != null) { foreach (ProjectPropertyGroupElement propertyGroup in propertyGroups) { if (!string.IsNullOrEmpty(propertyGroup.Condition)) { var cfgNameAndPlatform = ProjectConfig.ConfigAndPlatformOfCondition(propertyGroup.Condition); var cfgNme = ProjectConfig.GetConfigName(cfgNameAndPlatform); if (ProjectConfig.EqPlatform(cfgNameAndPlatform.Item2, clonePlatformName) && !dictionary.ContainsKey(cfgNme)) { dictionary.Add(cfgNme, propertyGroup); } } } } string[] propertiesConditionedOn = this.GetPropertiesConditionedOn("Configuration"); if (propertiesConditionedOn.Length == 0) { return(VSConstants.E_FAIL); } foreach (string configName in propertiesConditionedOn) { if (dictionary.Count <= 0 || dictionary.ContainsKey(configName)) { ProjectPropertyGroupElement newConfig = null; if (dictionary.ContainsKey(configName)) { newConfig = this.project.ClonePropertyGroup(dictionary[configName]); foreach (ProjectPropertyElement property in newConfig.Properties) { if (ProjectConfig.Eq(property.Name, "PlatformTarget") || ProjectConfig.Eq(property.Name, "Platform")) { property.Parent.RemoveChild(property); } } } else { this.PopulateEmptyConfig(ref newConfig); this.AddOutputPath(newConfig, configName); } newConfig.AddProperty("PlatformTarget", msbuildPlatform); newConfig.AddProperty("Platform", msbuildPlatform); newConfig.Condition = ProjectConfig.MakeMSBuildCondition(configName, msbuildPlatform); } } NotifyOnPlatformNameAdded(platformName); return(VSConstants.S_OK); }