Browse Source

Fixed SD2-923: PostBuildEvent element added at beginning of MSBuild project file

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1898 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
c2cc6b6453
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 4
      src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs
  3. 13
      src/Main/Base/Project/Src/Project/MSBuildEnums.cs
  4. 63
      src/Main/Base/Project/Src/Project/MSBuildProject.cs
  5. 36
      src/Main/Base/Project/Src/Project/PropertyGroup.cs
  6. 42
      src/Main/Base/Project/Src/Util/Linq.cs

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -712,6 +712,7 @@
<EmbeddedResource Include="Resources\ReverseIncrementalSearchCursor.cur" /> <EmbeddedResource Include="Resources\ReverseIncrementalSearchCursor.cur" />
<Compile Include="Src\Gui\Dialogs\SharpDevelopColorDialog.cs" /> <Compile Include="Src\Gui\Dialogs\SharpDevelopColorDialog.cs" />
<Compile Include="Src\Project\MSBuildImport.cs" /> <Compile Include="Src\Project\MSBuildImport.cs" />
<Compile Include="Src\Util\Linq.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj"> <ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj">

4
src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs

@ -369,7 +369,7 @@ namespace ICSharpCode.SharpDevelop.Project
#region Bind enum to ComboBox #region Bind enum to ComboBox
/// <summary> /// <summary>
/// Bind enum to ComboBox /// Bind enum to ComboBox. Assumes the first enum member is the default.
/// </summary> /// </summary>
public ConfigurationGuiBinding BindEnum<T>(string control, string property, params T[] values) where T : struct public ConfigurationGuiBinding BindEnum<T>(string control, string property, params T[] values) where T : struct
{ {
@ -377,7 +377,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
/// <summary> /// <summary>
/// Bind enum to ComboBox /// Bind enum to ComboBox. Assumes the first enum member is the default.
/// </summary> /// </summary>
public ConfigurationGuiBinding BindEnum<T>(Control control, string property, params T[] values) where T : struct public ConfigurationGuiBinding BindEnum<T>(Control control, string property, params T[] values) where T : struct
{ {

13
src/Main/Base/Project/Src/Project/MSBuildEnums.cs

@ -13,16 +13,18 @@ using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Project namespace ICSharpCode.SharpDevelop.Project
{ {
public enum RunPostBuildEvent { public enum RunPostBuildEvent
{
[Description("${res:Dialog.ProjectOptions.RunPostBuildEvent.OnSuccessfulBuild}")]
OnBuildSuccess,
[Description("${res:Dialog.ProjectOptions.RunPostBuildEvent.Always}")] [Description("${res:Dialog.ProjectOptions.RunPostBuildEvent.Always}")]
Always, Always,
[Description("${res:Dialog.ProjectOptions.RunPostBuildEvent.OnSuccessfulBuild}")]
OnSuccessfulBuild,
[Description("${res:Dialog.ProjectOptions.RunPostBuildEvent.OnOutputUpdated}")] [Description("${res:Dialog.ProjectOptions.RunPostBuildEvent.OnOutputUpdated}")]
OnOutputUpdated OnOutputUpdated
} }
public enum DebugSymbolType { public enum DebugSymbolType
{
[Description("${res:Dialog.ProjectOptions.DebugSymbolType.None}")] [Description("${res:Dialog.ProjectOptions.DebugSymbolType.None}")]
None, None,
[Description("${res:Dialog.ProjectOptions.DebugSymbolType.Full}")] [Description("${res:Dialog.ProjectOptions.DebugSymbolType.Full}")]
@ -31,7 +33,8 @@ namespace ICSharpCode.SharpDevelop.Project
PdbOnly PdbOnly
} }
public enum StartAction { public enum StartAction
{
Project, Project,
Program, Program,
StartURL StartURL

63
src/Main/Base/Project/Src/Project/MSBuildProject.cs

@ -28,6 +28,21 @@ namespace ICSharpCode.SharpDevelop.Project
protected char BuildConstantSeparator = ';'; protected char BuildConstantSeparator = ';';
/// <summary>
/// A list of project properties whose change causes reparsing of references and
/// files.
/// </summary>
protected readonly List<string> reparseSensitiveProperties = new List<string>();
/// <summary>
/// A list of project properties that are saved after the normal properties.
/// Use this for properties that could reference other properties, e.g.
/// PostBuildEvent references OutputPath.
/// </summary>
protected readonly List<string> lastSavedProperties = new List<string>(new string[]
{"PostBuildEvent",
"PreBuildEvent"});
/// <summary> /// <summary>
/// Gets the list of MSBuild Imports. /// Gets the list of MSBuild Imports.
/// </summary> /// </summary>
@ -236,7 +251,7 @@ namespace ICSharpCode.SharpDevelop.Project
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
BaseConfiguration["ProjectGuid"] = IdGuid; BaseConfiguration["ProjectGuid"] = IdGuid;
SaveProperties(writer, BaseConfiguration, configurations); SaveProperties(writer, BaseConfiguration, configurations, 1);
List<ProjectItem> references = new List<ProjectItem>(); List<ProjectItem> references = new List<ProjectItem>();
List<ProjectItem> imports = new List<ProjectItem>(); List<ProjectItem> imports = new List<ProjectItem>();
@ -289,6 +304,8 @@ namespace ICSharpCode.SharpDevelop.Project
writer.WriteEndElement(); writer.WriteEndElement();
} }
SaveProperties(writer, BaseConfiguration, configurations, 2);
writer.WriteEndElement(); writer.WriteEndElement();
} }
@ -300,36 +317,52 @@ namespace ICSharpCode.SharpDevelop.Project
writer.WriteStartElement("Project"); writer.WriteStartElement("Project");
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
SaveProperties(writer, UserBaseConfiguration, userConfigurations); SaveProperties(writer, UserBaseConfiguration, userConfigurations, 1);
SaveUnknownXmlSections(writer, userUnknownXmlSections); SaveUnknownXmlSections(writer, userUnknownXmlSections);
SaveProperties(writer, UserBaseConfiguration, userConfigurations, 2);
writer.WriteEndElement(); writer.WriteEndElement();
} }
} }
} }
static void SaveProperties(XmlWriter writer, PropertyGroup baseConfiguration, Dictionary<string, PropertyGroup> configurations) void SaveProperties(XmlWriter writer, PropertyGroup baseConfiguration, Dictionary<string, PropertyGroup> configurations, int runNumber)
{ {
Predicate<KeyValuePair<string, string>> filterPredicate;
if (runNumber == 1) {
filterPredicate = delegate(KeyValuePair<string, string> property) {
return !lastSavedProperties.Contains(property.Key);
};
} else {
filterPredicate = delegate(KeyValuePair<string, string> property) {
return lastSavedProperties.Contains(property.Key);
};
}
if (baseConfiguration.PropertyCount > 0) { if (baseConfiguration.PropertyCount > 0) {
writer.WriteStartElement("PropertyGroup"); PropertyGroup.WriteProperties(writer,
baseConfiguration.WriteProperties(writer); string.Empty,
writer.WriteEndElement(); Linq.Where(baseConfiguration, filterPredicate),
baseConfiguration.IsGuardedProperty);
} }
foreach (KeyValuePair<string, PropertyGroup> entry in configurations) { foreach (KeyValuePair<string, PropertyGroup> entry in configurations) {
// Skip empty groups // Skip empty groups
if (entry.Value.PropertyCount == 0) { if (entry.Value.PropertyCount == 0) {
continue; continue;
} }
writer.WriteStartElement("PropertyGroup"); string condition;
if (entry.Key.StartsWith("*|")) { if (entry.Key.StartsWith("*|")) {
writer.WriteAttributeString("Condition", " '$(Platform)' == '" + ProjectItem.MSBuildEscape(entry.Key.Substring(2)) + "' "); condition = " '$(Platform)' == '" + ProjectItem.MSBuildEscape(entry.Key.Substring(2)) + "' ";
} else if (entry.Key.EndsWith("|*")) { } else if (entry.Key.EndsWith("|*")) {
writer.WriteAttributeString("Condition", " '$(Configuration)' == '" + ProjectItem.MSBuildEscape(entry.Key.Substring(0, entry.Key.Length - 2)) + "' "); condition = " '$(Configuration)' == '" + ProjectItem.MSBuildEscape(entry.Key.Substring(0, entry.Key.Length - 2)) + "' ";
} else { } else {
writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + ProjectItem.MSBuildEscape(entry.Key) + "' "); condition = " '$(Configuration)|$(Platform)' == '" + ProjectItem.MSBuildEscape(entry.Key) + "' ";
} }
entry.Value.WriteProperties(writer); PropertyGroup.WriteProperties(writer,
writer.WriteEndElement(); condition,
Linq.Where(entry.Value, filterPredicate),
entry.Value.IsGuardedProperty);
} }
} }
@ -514,12 +547,6 @@ namespace ICSharpCode.SharpDevelop.Project
Items.Count); Items.Count);
} }
/// <summary>
/// A list of project properties whose change causes reparsing of references and
/// files.
/// </summary>
protected readonly List<string> reparseSensitiveProperties = new List<string>();
[ReadOnly(true)] [ReadOnly(true)]
[LocalizedProperty("${res:Dialog.ProjectOptions.Platform}")] [LocalizedProperty("${res:Dialog.ProjectOptions.Platform}")]
public override string Platform { public override string Platform {

36
src/Main/Base/Project/Src/Project/PropertyGroup.cs

@ -19,6 +19,7 @@ namespace ICSharpCode.SharpDevelop.Project
public sealed class PropertyGroup : IEnumerable<KeyValuePair<string, string>>, ICloneable public sealed class PropertyGroup : IEnumerable<KeyValuePair<string, string>>, ICloneable
{ {
// TODO: Isn't MSBuild case-insensitive ??? // TODO: Isn't MSBuild case-insensitive ???
// TODO: merge both dictionaries into one using a custom class
Dictionary<string, bool> isGuardedProperty = new Dictionary<string, bool>(); Dictionary<string, bool> isGuardedProperty = new Dictionary<string, bool>();
Dictionary<string, string> properties = new Dictionary<string, string>(); Dictionary<string, string> properties = new Dictionary<string, string>();
@ -40,6 +41,12 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
internal Dictionary<string, bool> IsGuardedProperty {
get {
return isGuardedProperty;
}
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator() public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{ {
return properties.GetEnumerator(); return properties.GetEnumerator();
@ -170,7 +177,32 @@ namespace ICSharpCode.SharpDevelop.Project
internal void WriteProperties(XmlWriter writer) internal void WriteProperties(XmlWriter writer)
{ {
WriteProperties(writer, null, properties, isGuardedProperty);
}
/// <summary>
/// Writes a set of properties into the XmlWriter.
/// A &lt;PropertyGroup&gt; tag is created around the properties
/// if there are more than 0 properties. This PropertyGroup has the specified condition,
/// or no condition if condition is string.Empty.
/// <b>If condition is null, no &lt;PropertyGroup&gt; tag is created!!</b>
/// </summary>
internal static void WriteProperties(XmlWriter writer,
string condition,
IEnumerable<KeyValuePair<string, string>> properties,
Dictionary<string, bool> isGuardedProperty)
{
bool first = true;
foreach (KeyValuePair<string, string> entry in properties) { foreach (KeyValuePair<string, string> entry in properties) {
if (first) {
first = false;
if (condition != null) {
writer.WriteStartElement("PropertyGroup");
if (condition.Length > 0) {
writer.WriteAttributeString("Condition", condition);
}
}
}
writer.WriteStartElement(entry.Key); writer.WriteStartElement(entry.Key);
if (isGuardedProperty.ContainsKey(entry.Key) && isGuardedProperty[entry.Key]) { if (isGuardedProperty.ContainsKey(entry.Key) && isGuardedProperty[entry.Key]) {
@ -182,6 +214,10 @@ namespace ICSharpCode.SharpDevelop.Project
} }
writer.WriteEndElement(); writer.WriteEndElement();
} }
if (!first && condition != null) {
// a property group was created, so close it:
writer.WriteEndElement();
}
} }
} }
} }

42
src/Main/Base/Project/Src/Util/Linq.cs

@ -0,0 +1,42 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// A set of methods that replicate some of the LINQ functionality.
/// </summary>
/// <remarks>
/// Will be removed when SharpDevelop is compiled with C# 3.0.
/// </remarks>
public static class Linq
{
/// <summary>
/// Applies a conversion function to all elements in the input.
/// </summary>
public static IEnumerable<S> Select<T, S>(IEnumerable<T> input, Converter<T, S> converter)
{
foreach (T element in input) {
yield return converter(element);
}
}
/// <summary>
/// Returns only the elements in input for which filter is true.
/// </summary>
public static IEnumerable<T> Where<T>(IEnumerable<T> input, Predicate<T> filter)
{
foreach (T element in input) {
if (filter(element))
yield return element;
}
}
}
}
Loading…
Cancel
Save