Browse Source

FixSolutionConfiguration() no longer creates new solution configurations when adding a project to an existing solution.

pull/24/merge
Daniel Grunwald 13 years ago
parent
commit
c90716894e
  1. 1
      src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs
  2. 82
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  3. 14
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

1
src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs

@ -312,7 +312,6 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -312,7 +312,6 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
string solutionLocation = projectCreateInformation.Solution.FileName;
if (createNewSolution) {
projectCreateInformation.Solution.AddFolder(project);
projectCreateInformation.Solution.FixSolutionConfiguration(new IProject[] {project});
projectCreateInformation.Solution.Save();
ProjectService.OnSolutionCreated(new SolutionEventArgs(projectCreateInformation.Solution));
projectCreateInformation.Solution.Dispose();

82
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -270,22 +270,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -270,22 +270,7 @@ namespace ICSharpCode.SharpDevelop.Project
{
IProject project = folder as IProject;
if (project != null && !isLoading) {
var projectConfigurations = project.ConfigurationNames;
var solutionConfigurations = this.GetConfigurationNames();
var projectPlatforms = project.PlatformNames;
var solutionPlatforms = this.GetPlatformNames();
foreach (string config in solutionConfigurations) {
string projectConfig = config;
if (!projectConfigurations.Contains(projectConfig))
projectConfig = projectConfigurations.FirstOrDefault() ?? "Debug";
foreach (string platform in solutionPlatforms) {
string projectPlatform = FixPlatformNameForProject(platform);
if (!projectPlatforms.Contains(projectPlatform))
projectPlatform = projectPlatforms.FirstOrDefault() ?? "AnyCPU";
CreateMatchingItem(config, platform, project, projectConfig + "|" + FixPlatformNameForSolution(projectPlatform));
}
}
FixSolutionConfiguration(new[] { project });
}
}
@ -694,38 +679,59 @@ namespace ICSharpCode.SharpDevelop.Project @@ -694,38 +679,59 @@ namespace ICSharpCode.SharpDevelop.Project
return new SolutionItem("Debug|Any CPU", "Debug|Any CPU");
}
/// <summary>
/// Repairs the solution configuration to project configuration mapping for the specified projects.
/// </summary>
public bool FixSolutionConfiguration(IEnumerable<IProject> projects)
{
ProjectSection solSec = GetSolutionConfigurationsSection();
ProjectSection prjSec = GetProjectConfigurationsSection();
bool changed = false;
SortedSet<string> configurations = new SortedSet<string>();
foreach (IProject project in projects) {
string guid = project.IdGuid.ToUpperInvariant();
string platform = FixPlatformNameForSolution(project.ActivePlatform);
foreach (string configuration in new string[]{"Debug", "Release"}) {
string key = configuration + "|" + platform;
configurations.Add(key);
string searchKey = guid + "." + key + ".Build.0";
if (!prjSec.Items.Exists(item => item.Name == searchKey)) {
prjSec.Items.Add(new SolutionItem(searchKey, key));
changed = true;
}
searchKey = guid + "." + key + ".ActiveCfg";
if (!prjSec.Items.Exists(item => item.Name == searchKey)) {
prjSec.Items.Add(new SolutionItem(searchKey, key));
var solutionConfigurations = this.GetConfigurationNames();
var solutionPlatforms = this.GetPlatformNames();
// Create configurations/platforms if none exist
if (solutionConfigurations.Count == 0) {
solutionConfigurations.Add("Debug");
solutionConfigurations.Add("Release");
}
if (solutionPlatforms.Count == 0) {
solutionPlatforms.Add("Any CPU");
}
// Ensure all solution configurations/platforms exist in the SolutionConfigurationPlatforms section:
foreach (string config in solutionConfigurations) {
foreach (string platform in solutionPlatforms) {
string key = config + "|" + platform;
if (!solSec.Items.Exists(item => key.Equals(item.Location, StringComparison.OrdinalIgnoreCase) && key.Equals(item.Name, StringComparison.OrdinalIgnoreCase))) {
solSec.Items.Add(new SolutionItem(key, key));
changed = true;
}
}
}
foreach (string key in configurations) {
if (!solSec.Items.Exists(item => item.Location == key && item.Name == key)) {
solSec.Items.Add(new SolutionItem(key, key));
changed = true;
// Ensure all solution configurations/platforms are mapped to a project configuration:
foreach (var project in projects) {
string guid = project.IdGuid.ToUpperInvariant();
var projectConfigurations = project.ConfigurationNames;
var projectPlatforms = project.PlatformNames;
foreach (string config in solutionConfigurations) {
string projectConfig = config;
if (!projectConfigurations.Contains(projectConfig))
projectConfig = projectConfigurations.FirstOrDefault() ?? "Debug";
foreach (string platform in solutionPlatforms) {
string activeCfgKey = guid + "." + config + "|" + platform + ".ActiveCfg";
// Only add the mapping if the ActiveCfg is not specified.
// If ActiveCfg is specific but Build.0 isn't, we don't add the Build.0.
if (!prjSec.Items.Exists(item => activeCfgKey.Equals(item.Name, StringComparison.OrdinalIgnoreCase))) {
string projectPlatform = FixPlatformNameForProject(platform);
if (!projectPlatforms.Contains(projectPlatform))
projectPlatform = projectPlatforms.FirstOrDefault() ?? "AnyCPU";
changed = true;
CreateMatchingItem(config, platform, project, projectConfig + "|" + FixPlatformNameForSolution(projectPlatform));
}
}
}
}

14
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -204,7 +204,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -204,7 +204,6 @@ namespace ICSharpCode.SharpDevelop.Project
}
solutionFolderNode.Container.AddFolder(newProject);
ParserService.CreateProjectContentForAddedProject(newProject);
solutionFolderNode.Solution.FixSolutionConfiguration(new IProject[] { newProject });
OnProjectAdded(new ProjectEventArgs(newProject));
}
@ -412,19 +411,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -412,19 +411,6 @@ namespace ICSharpCode.SharpDevelop.Project
return;
}
solution.AddFolder(project);
ProjectSection configSection = solution.GetSolutionConfigurationsSection();
foreach (string configuration in project.ConfigurationNames) {
foreach (string platform in project.PlatformNames) {
string key;
if (platform == "AnyCPU") { // Fix for SD2-786
key = configuration + "|Any CPU";
} else {
key = configuration + "|" + platform;
}
configSection.Items.Add(new SolutionItem(key, key));
}
}
solution.FixSolutionConfiguration(new IProject[] { project });
if (FileUtility.ObservedSave((NamedFileOperationDelegate)solution.Save, solutionFile) == FileOperationResult.OK) {
// only load when saved succesfully

Loading…
Cancel
Save