Browse Source

SD-1605 - Reimplement editing project and solution configurations

4.0
Daniel Grunwald 14 years ago
parent
commit
4a474f4b35
  1. 109
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

109
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -13,7 +13,6 @@ using System.Xml;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project.Converter;
using Microsoft.Build.Construction; using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation; using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions; using Microsoft.Build.Exceptions;
@ -29,7 +28,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// require locking on the SyncRoot. Methods that return underlying MSBuild objects require that /// require locking on the SyncRoot. Methods that return underlying MSBuild objects require that
/// the caller locks on the SyncRoot. /// the caller locks on the SyncRoot.
/// </summary> /// </summary>
public class MSBuildBasedProject : AbstractProject, IProjectItemListProvider public class MSBuildBasedProject : AbstractProject, IProjectItemListProvider, IProjectAllowChangeConfigurations
{ {
/// <summary> /// <summary>
/// The project collection that contains this project. /// The project collection that contains this project.
@ -1370,19 +1369,17 @@ namespace ICSharpCode.SharpDevelop.Project
#endregion #endregion
#region IProjectAllowChangeConfigurations interface implementation #region IProjectAllowChangeConfigurations interface implementation
/*
bool IProjectAllowChangeConfigurations.RenameProjectConfiguration(string oldName, string newName) bool IProjectAllowChangeConfigurations.RenameProjectConfiguration(string oldName, string newName)
{ {
lock (SyncRoot) { lock (SyncRoot) {
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) { foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.Concat(userProjectFile.PropertyGroups)) {
if (g.IsImported) { // Rename the default configuration setting
continue; var prop = g.Properties.FirstOrDefault(p => p.Name == "Configuration");
} if (prop != null && prop.Value == oldName) {
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Configuration");
if (prop != null && prop.Value == oldName) {
prop.Value = newName; prop.Value = newName;
} }
// Rename the configuration in conditions
string gConfiguration, gPlatform; string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition, MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration, out gConfiguration,
@ -1399,15 +1396,14 @@ namespace ICSharpCode.SharpDevelop.Project
bool IProjectAllowChangeConfigurations.RenameProjectPlatform(string oldName, string newName) bool IProjectAllowChangeConfigurations.RenameProjectPlatform(string oldName, string newName)
{ {
lock (SyncRoot) { lock (SyncRoot) {
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) { foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.Concat(userProjectFile.PropertyGroups)) {
if (g.IsImported) { // Rename the default platform setting
continue; var prop = g.Properties.FirstOrDefault(p => p.Name == "Platform");
} if (prop != null && prop.Value == oldName) {
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Platform");
if (prop != null && prop.Value == oldName) {
prop.Value = newName; prop.Value = newName;
} }
// Rename the platform in conditions
string gConfiguration, gPlatform; string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition, MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration, out gConfiguration,
@ -1424,27 +1420,30 @@ namespace ICSharpCode.SharpDevelop.Project
bool IProjectAllowChangeConfigurations.AddProjectConfiguration(string newName, string copyFrom) bool IProjectAllowChangeConfigurations.AddProjectConfiguration(string newName, string copyFrom)
{ {
lock (SyncRoot) { lock (SyncRoot) {
bool copiedGroup = false; bool copiedGroupInMainFile = false;
if (copyFrom != null) { if (copyFrom != null) {
foreach (MSBuild.BuildPropertyGroup g foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.ToList()) {
in project.PropertyGroups.Cast<MSBuild.BuildPropertyGroup>().ToList()) string gConfiguration, gPlatform;
{ MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
if (g.IsImported) { out gConfiguration,
continue; out gPlatform);
if (gConfiguration == copyFrom) {
CopyProperties(projectFile, g, newName, gPlatform);
copiedGroupInMainFile = true;
} }
}
foreach (ProjectPropertyGroupElement g in userProjectFile.PropertyGroups.ToList()) {
string gConfiguration, gPlatform; string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition, MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration, out gConfiguration,
out gPlatform); out gPlatform);
if (gConfiguration == copyFrom) { if (gConfiguration == copyFrom) {
CopyProperties(g, newName, gPlatform); CopyProperties(userProjectFile, g, newName, gPlatform);
copiedGroup = true;
} }
} }
} }
if (!copiedGroup) { if (!copiedGroupInMainFile) {
project.AddNewPropertyGroup(false).Condition = CreateCondition(newName, null); projectFile.AddPropertyGroup().Condition = CreateCondition(newName, null);
} }
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
return true; return true;
@ -1454,27 +1453,30 @@ namespace ICSharpCode.SharpDevelop.Project
bool IProjectAllowChangeConfigurations.AddProjectPlatform(string newName, string copyFrom) bool IProjectAllowChangeConfigurations.AddProjectPlatform(string newName, string copyFrom)
{ {
lock (SyncRoot) { lock (SyncRoot) {
bool copiedGroup = false; bool copiedGroupInMainFile = false;
if (copyFrom != null) { if (copyFrom != null) {
foreach (MSBuild.BuildPropertyGroup g foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.ToList()) {
in project.PropertyGroups.Cast<MSBuild.BuildPropertyGroup>().ToList()) string gConfiguration, gPlatform;
{ MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
if (g.IsImported) { out gConfiguration,
continue; out gPlatform);
if (gPlatform == copyFrom) {
CopyProperties(projectFile, g, gConfiguration, newName);
copiedGroupInMainFile = true;
} }
}
foreach (ProjectPropertyGroupElement g in userProjectFile.PropertyGroups.ToList()) {
string gConfiguration, gPlatform; string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition, MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration, out gConfiguration,
out gPlatform); out gPlatform);
if (gPlatform == copyFrom) { if (gPlatform == copyFrom) {
CopyProperties(g, gConfiguration, newName); CopyProperties(userProjectFile, g, gConfiguration, newName);
copiedGroup = true;
} }
} }
} }
if (!copiedGroup) { if (!copiedGroupInMainFile) {
project.AddNewPropertyGroup(false).Condition = CreateCondition(null, newName); projectFile.AddPropertyGroup().Condition = CreateCondition(null, newName);
} }
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
return true; return true;
@ -1484,12 +1486,12 @@ namespace ICSharpCode.SharpDevelop.Project
/// <summary> /// <summary>
/// copy properties from g into a new property group for newConfiguration and newPlatform /// copy properties from g into a new property group for newConfiguration and newPlatform
/// </summary> /// </summary>
void CopyProperties(MSBuild.BuildPropertyGroup g, string newConfiguration, string newPlatform) void CopyProperties(ProjectRootElement project, ProjectPropertyGroupElement g, string newConfiguration, string newPlatform)
{ {
MSBuild.BuildPropertyGroup ng = project.AddNewPropertyGroup(false); ProjectPropertyGroupElement ng = project.AddPropertyGroup();
ng.Condition = CreateCondition(newConfiguration, newPlatform); ng.Condition = CreateCondition(newConfiguration, newPlatform);
foreach (MSBuild.BuildProperty p in g) { foreach (var p in g.Properties) {
ng.AddNewProperty(p.Name, p.Value); ng.AddProperty(p.Name, p.Value).Condition = p.Condition;
} }
} }
@ -1506,14 +1508,8 @@ namespace ICSharpCode.SharpDevelop.Project
if (otherConfigurationName == null) { if (otherConfigurationName == null) {
throw new InvalidOperationException("cannot remove the last configuration"); throw new InvalidOperationException("cannot remove the last configuration");
} }
foreach (MSBuild.BuildPropertyGroup g foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.Concat(userProjectFile.PropertyGroups).ToList()) {
in project.PropertyGroups.Cast<MSBuild.BuildPropertyGroup>().ToList()) ProjectPropertyElement prop = g.Properties.FirstOrDefault(p => p.Name == "Configuration");
{
if (g.IsImported) {
continue;
}
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Configuration");
if (prop != null && prop.Value == name) { if (prop != null && prop.Value == name) {
prop.Value = otherConfigurationName; prop.Value = otherConfigurationName;
} }
@ -1523,7 +1519,7 @@ namespace ICSharpCode.SharpDevelop.Project
out gConfiguration, out gConfiguration,
out gPlatform); out gPlatform);
if (gConfiguration == name) { if (gConfiguration == name) {
project.RemovePropertyGroup(g); g.Parent.RemoveChild(g);
} }
} }
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
@ -1544,14 +1540,8 @@ namespace ICSharpCode.SharpDevelop.Project
if (otherPlatformName == null) { if (otherPlatformName == null) {
throw new InvalidOperationException("cannot remove the last platform"); throw new InvalidOperationException("cannot remove the last platform");
} }
foreach (MSBuild.BuildPropertyGroup g foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.Concat(userProjectFile.PropertyGroups).ToList()) {
in project.PropertyGroups.Cast<MSBuild.BuildPropertyGroup>().ToList()) ProjectPropertyElement prop = g.Properties.FirstOrDefault(p => p.Name == "Platform");
{
if (g.IsImported) {
continue;
}
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Platform");
if (prop != null && prop.Value == name) { if (prop != null && prop.Value == name) {
prop.Value = otherPlatformName; prop.Value = otherPlatformName;
} }
@ -1561,14 +1551,13 @@ namespace ICSharpCode.SharpDevelop.Project
out gConfiguration, out gConfiguration,
out gPlatform); out gPlatform);
if (gPlatform == name) { if (gPlatform == name) {
project.RemovePropertyGroup(g); g.Parent.RemoveChild(g);
} }
} }
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
return true; return true;
} }
} }
*/
#endregion #endregion
} }
} }

Loading…
Cancel
Save