/// <summary>
/// Assigns a new name to a configuration.
/// </summary>
/// <param name="old">The old name of the target configuration.</param>
/// <param name="newname">The new name of the target configuration.</param>
/// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
public virtual int RenameCfgsOfCfgName(string old, string newname)
{
this.project.BuildProject.ReevaluateIfNecessary();
foreach (ProjectPropertyGroupElement current in this.project.BuildProject.Xml.PropertyGroups)
{
if (string.IsNullOrEmpty(current.Condition))
{
continue;
}
var cfgNameAndPlatform = ProjectConfig.ConfigAndPlatformOfCondition(current.Condition);
if (ProjectConfig.Eq(ProjectConfig.GetConfigName(cfgNameAndPlatform), old))
{
//ConfigCanonicalName key2 = new ConfigCanonicalName(newname, key.Platform);
current.Condition = ProjectConfig.MakeMSBuildCondition(newname, cfgNameAndPlatform.Item2);
var outputPath = current.Properties.Where(p => p.Name == "OutputPath").FirstOrDefault();
if (outputPath != null && outputPath.Value != null)
{
string path = this.ProjectMgr.OutputBaseRelativePath;
if (path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
{
path = Path.GetDirectoryName(path);
}
if (string.Equals(Path.Combine(path, old), outputPath.Value, StringComparison.OrdinalIgnoreCase))
{
current.SetProperty("OutputPath", Path.Combine(path, newname));
}
}
var oldKey = ProjectConfig.MakeConfigKey(cfgNameAndPlatform);
if (this.configurationsList.ContainsKey(oldKey))
{
ProjectConfig projectConfig = this.configurationsList[oldKey];
this.configurationsList.Remove(oldKey);
this.configurationsList.Add(ProjectConfig.MakeConfigKey(newname, cfgNameAndPlatform.Item2), projectConfig);
projectConfig.ConfigurationName = newname;
}
}
}
this.NotifyOnCfgNameRenamed(old, newname);
//// First create the condition that represent the configuration we want to rename
//string condition = String.Format(CultureInfo.InvariantCulture, configString, old).Trim();
//foreach (ProjectPropertyGroupElement config in this.project.BuildProject.Xml.PropertyGroups)
//{
// // Only care about conditional property groups
// if (config.Condition == null || config.Condition.Length == 0)
// continue;
// // Skip if it isn't the group we want
// if (String.Compare(config.Condition.Trim(), condition, StringComparison.OrdinalIgnoreCase) != 0)
// continue;
// // Change the name
// config.Condition = String.Format(CultureInfo.InvariantCulture, configString, newname);
// // Update the name in our config list
// if (configurationsList.ContainsKey(old))
// {
// ProjectConfig configuration = configurationsList[old];
// configurationsList.Remove(old);
// configurationsList.Add(newname, configuration);
// // notify the configuration of its new name
// configuration.ConfigurationName = newname;
// }
// NotifyOnCfgNameRenamed(old, newname);
//}
return(VSConstants.S_OK);
}