Browse Source

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

pull/24/merge
Daniel Grunwald 14 years ago
parent
commit
c90716894e
  1. 1
      src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs
  2. 78
      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
string solutionLocation = projectCreateInformation.Solution.FileName; string solutionLocation = projectCreateInformation.Solution.FileName;
if (createNewSolution) { if (createNewSolution) {
projectCreateInformation.Solution.AddFolder(project); projectCreateInformation.Solution.AddFolder(project);
projectCreateInformation.Solution.FixSolutionConfiguration(new IProject[] {project});
projectCreateInformation.Solution.Save(); projectCreateInformation.Solution.Save();
ProjectService.OnSolutionCreated(new SolutionEventArgs(projectCreateInformation.Solution)); ProjectService.OnSolutionCreated(new SolutionEventArgs(projectCreateInformation.Solution));
projectCreateInformation.Solution.Dispose(); projectCreateInformation.Solution.Dispose();

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

@ -270,22 +270,7 @@ namespace ICSharpCode.SharpDevelop.Project
{ {
IProject project = folder as IProject; IProject project = folder as IProject;
if (project != null && !isLoading) { if (project != null && !isLoading) {
var projectConfigurations = project.ConfigurationNames; FixSolutionConfiguration(new[] { project });
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));
}
}
} }
} }
@ -694,38 +679,59 @@ namespace ICSharpCode.SharpDevelop.Project
return new SolutionItem("Debug|Any CPU", "Debug|Any CPU"); 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) public bool FixSolutionConfiguration(IEnumerable<IProject> projects)
{ {
ProjectSection solSec = GetSolutionConfigurationsSection(); ProjectSection solSec = GetSolutionConfigurationsSection();
ProjectSection prjSec = GetProjectConfigurationsSection(); ProjectSection prjSec = GetProjectConfigurationsSection();
bool changed = false; bool changed = false;
SortedSet<string> configurations = new SortedSet<string>(); var solutionConfigurations = this.GetConfigurationNames();
var solutionPlatforms = this.GetPlatformNames();
foreach (IProject project in projects) { // Create configurations/platforms if none exist
string guid = project.IdGuid.ToUpperInvariant(); if (solutionConfigurations.Count == 0) {
string platform = FixPlatformNameForSolution(project.ActivePlatform); solutionConfigurations.Add("Debug");
foreach (string configuration in new string[]{"Debug", "Release"}) { solutionConfigurations.Add("Release");
string key = configuration + "|" + platform; }
configurations.Add(key); if (solutionPlatforms.Count == 0) {
solutionPlatforms.Add("Any CPU");
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"; // Ensure all solution configurations/platforms exist in the SolutionConfigurationPlatforms section:
if (!prjSec.Items.Exists(item => item.Name == searchKey)) { foreach (string config in solutionConfigurations) {
prjSec.Items.Add(new SolutionItem(searchKey, key)); 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; changed = true;
} }
} }
} }
foreach (string key in configurations) { // Ensure all solution configurations/platforms are mapped to a project configuration:
if (!solSec.Items.Exists(item => item.Location == key && item.Name == key)) { foreach (var project in projects) {
solSec.Items.Add(new SolutionItem(key, key)); string guid = project.IdGuid.ToUpperInvariant();
changed = true; 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
} }
solutionFolderNode.Container.AddFolder(newProject); solutionFolderNode.Container.AddFolder(newProject);
ParserService.CreateProjectContentForAddedProject(newProject); ParserService.CreateProjectContentForAddedProject(newProject);
solutionFolderNode.Solution.FixSolutionConfiguration(new IProject[] { newProject });
OnProjectAdded(new ProjectEventArgs(newProject)); OnProjectAdded(new ProjectEventArgs(newProject));
} }
@ -412,19 +411,6 @@ namespace ICSharpCode.SharpDevelop.Project
return; return;
} }
solution.AddFolder(project); 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) { if (FileUtility.ObservedSave((NamedFileOperationDelegate)solution.Save, solutionFile) == FileOperationResult.OK) {
// only load when saved succesfully // only load when saved succesfully

Loading…
Cancel
Save