From e1cc2ab2e4e25a2e4821919a671eee2f31d76326 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Tue, 16 Nov 2010 22:14:21 +0000 Subject: [PATCH] Fix SD-1718 - Post build events not added to end of project file. --- .../Src/Project/MSBuildBasedProject.cs | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs index 51c9787742..71be7d3c94 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs @@ -839,18 +839,50 @@ namespace ICSharpCode.SharpDevelop.Project } } } - foreach (var propertyGroup in targetProject.PropertyGroups) { - if (propertyGroup.Condition == groupCondition) { - propertyGroup.AddProperty(propertyName, newValue); - return; - } + + var matchedPropertyGroup = FindPropertyGroup(targetProject, groupCondition, position); + if (matchedPropertyGroup != null) { + matchedPropertyGroup.AddProperty(propertyName, newValue); + return; } - var newGroup = targetProject.AddPropertyGroup(); + var newGroup = AddNewPropertyGroup(targetProject, position); newGroup.Condition = groupCondition; newGroup.AddProperty(propertyName, newValue); } + ProjectPropertyGroupElement FindPropertyGroup(ProjectRootElement targetProject, string groupCondition, PropertyPosition position) + { + ProjectPropertyGroupElement matchedPropertyGroup = null; + foreach (var projectItem in targetProject.Children) { + ProjectPropertyGroupElement propertyGroup = projectItem as ProjectPropertyGroupElement; + if (propertyGroup != null) { + if (propertyGroup.Condition == groupCondition) { + matchedPropertyGroup = propertyGroup; + if (position != PropertyPosition.UseExistingOrCreateAfterLastImport) { + return matchedPropertyGroup; + } + } + } + if (position == PropertyPosition.UseExistingOrCreateAfterLastImport) { + if (projectItem is ProjectImportElement) { + matchedPropertyGroup = null; + } + } + } + return matchedPropertyGroup; + } + + ProjectPropertyGroupElement AddNewPropertyGroup(ProjectRootElement targetProject, PropertyPosition position) + { + if (position == PropertyPosition.UseExistingOrCreateAfterLastImport) { + var propertyGroup = targetProject.CreatePropertyGroupElement(); + targetProject.AppendChild(propertyGroup); + return propertyGroup; + } + return targetProject.AddPropertyGroup(); + } + /// /// Removes the property from all configurations and platforms. ///