Browse Source

Fixed SD2-1020: Nameing project folders with ';' makes the solution unable to run.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1727 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
d154f02884
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 2
      src/Main/Base/Project/Src/Project/Converter/PrjxToSolutionProject.cs
  3. 60
      src/Main/Base/Project/Src/Project/Items/ProjectItem.cs
  4. 108
      src/Main/Base/Project/Src/Project/MSBuildFile.cs
  5. 26
      src/Main/Base/Project/Src/Project/MSBuildProject.cs
  6. 4
      src/Main/Base/Project/Src/Project/PropertyGroup.cs
  7. 4
      src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

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

@ -646,7 +646,6 @@
<Compile Include="Src\TextEditor\Gui\Editor\CompletionWindow\OverrideCompletionDataProvider.cs" /> <Compile Include="Src\TextEditor\Gui\Editor\CompletionWindow\OverrideCompletionDataProvider.cs" />
<Compile Include="Src\Gui\Pads\TaskList\TaskView.cs" /> <Compile Include="Src\Gui\Pads\TaskList\TaskView.cs" />
<Compile Include="Src\Gui\Pads\TaskList\TaskListPad.cs" /> <Compile Include="Src\Gui\Pads\TaskList\TaskListPad.cs" />
<Compile Include="Src\Project\MSBuildFile.cs" />
<Compile Include="Src\Gui\FormLocationHelper.cs" /> <Compile Include="Src\Gui\FormLocationHelper.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\AddWebReferenceDialog.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\AddWebReferenceDialog.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\WebServicesView.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\WebServicesView.cs" />

2
src/Main/Base/Project/Src/Project/Converter/PrjxToSolutionProject.cs

@ -236,7 +236,7 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
} }
// We have to use the stringWriter for writing because xslt.Transform doesn't use // We have to use the stringWriter for writing because xslt.Transform doesn't use
// writer.Formatting. Also, we need to remove some unwanted whitespace from the beginning. // writer.Formatting. Also, we need to remove some unwanted whitespace from the beginning.
using (MSBuildFileWriter writer = new MSBuildFileWriter(outFile, Encoding.UTF8)) { using (XmlTextWriter writer = new XmlTextWriter(outFile, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented; writer.Formatting = Formatting.Indented;
using (XmlTextReader reader = new XmlTextReader(new StringReader(stringWriter.ToString()))) { using (XmlTextReader reader = new XmlTextReader(new StringReader(stringWriter.ToString()))) {
reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.WhitespaceHandling = WhitespaceHandling.Significant;

60
src/Main/Base/Project/Src/Project/Items/ProjectItem.cs

@ -6,6 +6,8 @@
// </file> // </file>
using System; using System;
using System.Globalization;
using System.Text;
using System.IO; using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
@ -138,10 +140,60 @@ namespace ICSharpCode.SharpDevelop.Project
Properties); Properties);
} }
public static string MSBuildEscape(string text)
{
StringBuilder b = null;
for (int i = 0; i < text.Length; i++) {
char c = text[i];
if (c == '%') {
if (b == null) b = new StringBuilder(text, 0, i, text.Length + 6);
b.Append("%25");
} else if (c == ';') {
if (b == null) b = new StringBuilder(text, 0, i, text.Length + 6);
b.Append("%3b");
} else {
if (b != null) {
b.Append(c);
}
}
}
if (b != null)
return b.ToString();
else
return text;
}
public static string MSBuildUnescape(string text)
{
StringBuilder b = null;
for (int i = 0; i < text.Length; i++) {
char c = text[i];
if (c == '%' && i + 2 < text.Length) {
if (b == null) b = new StringBuilder(text, 0, i, text.Length + 6);
string a = text[i + 1].ToString() + text[i + 2].ToString();
int num;
if (int.TryParse(a, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out num)) {
b.Append((char)num);
i += 2;
} else {
b.Append('%');
}
} else {
if (b != null) {
b.Append(c);
}
}
}
if (b != null)
return b.ToString();
else
return text;
}
public static ProjectItem ReadItem(XmlReader reader, IProject project, string itemType) public static ProjectItem ReadItem(XmlReader reader, IProject project, string itemType)
{ {
ProjectItem newItem = project != null ? project.CreateProjectItem(itemType) : ProjectItemFactory.CreateProjectItem(project, itemType); ProjectItem newItem = project != null ? project.CreateProjectItem(itemType) : ProjectItemFactory.CreateProjectItem(project, itemType);
newItem.Include = reader.GetAttribute("Include"); newItem.Include = MSBuildUnescape(reader.GetAttribute("Include"));
if (!reader.IsEmptyElement) { if (!reader.IsEmptyElement) {
PropertyGroup.ReadProperties(reader, newItem.Properties, itemType); PropertyGroup.ReadProperties(reader, newItem.Properties, itemType);
} }
@ -152,12 +204,12 @@ namespace ICSharpCode.SharpDevelop.Project
internal void WriteItem(XmlWriter writer) internal void WriteItem(XmlWriter writer)
{ {
writer.WriteStartElement(Tag); writer.WriteStartElement(Tag);
writer.WriteAttributeString("Include", Include); writer.WriteAttributeString("Include", MSBuildEscape(Include));
Properties.WriteProperties(writer); this.Properties.WriteProperties(writer);
writer.WriteEndElement(); writer.WriteEndElement();
} }
internal static void ReadItemGroup(XmlTextReader reader, IProject project, List<ProjectItem> items) internal static void ReadItemGroup(XmlReader reader, IProject project, List<ProjectItem> items)
{ {
if (reader.IsEmptyElement) { if (reader.IsEmptyElement) {
return; return;

108
src/Main/Base/Project/Src/Project/MSBuildFile.cs

@ -1,108 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Scott Ferrett" email="surf@softvelocity.com"/>
// <version>$Revision$</version>
// </file>
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Globalization;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Xsl;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Project
{
// Summary:
// Represents a reader that reads MSBuild files converting the MSBuild specific escape %25 to %
public class MSBuildFileReader : XmlTextReader
{
private string Convert(string instr)
{
if (instr != null && instr.Contains("%25")) {
return instr.Replace("%25", "%");
}
return instr;
}
public MSBuildFileReader(string fileName) : base(fileName) { }
public MSBuildFileReader(TextReader r) : base(r) { }
//
// Summary:
// Gets the value of the attribute with the specified index.
//
// Parameters:
// i:
// The index of the attribute. The index is zero-based. (The first attribute
// has index 0.)
//
// Returns:
// The value of the specified attribute.
//
// Exceptions:
// System.ArgumentOutOfRangeException
//
public override string GetAttribute(int i)
{
return Convert(base.GetAttribute(i));
}
//
// Summary:
// Gets the value of the attribute with the specified name.
//
// Parameters:
// name:
// The qualified name of the attribute.
//
// Returns:
// The value of the specified attribute. If the attribute is not found, null is
// returned.
public override string GetAttribute(string name)
{
return Convert(base.GetAttribute(name));
}
//
// Summary:
// Gets the value of the attribute with the specified local name and namespace
// URI.
//
// Parameters:
// localName:
// The local name of the attribute.
// namespaceURI:
// The namespace URI of the attribute.
//
// Returns:
// The value of the specified attribute. If the attribute is not found, null is
// returned. This method does not move the reader.
public override string GetAttribute(string localName, string namespaceURI)
{
return Convert(base.GetAttribute(localName, namespaceURI));
}
}
// Summary:
// Represents a writer that writes MSBuild files converting the MSBuild specific escape % to %25
public class MSBuildFileWriter : XmlTextWriter
{
private string Convert(string instr)
{
if (instr != null && instr.Contains("%")) {
return instr.Replace("%", "%25");
}
return instr;
}
public MSBuildFileWriter(string fileName, Encoding encoding) : base(fileName, encoding) { }
public override void WriteString(string text)
{
base.WriteString(Convert(text));
}
}
}

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

@ -90,7 +90,7 @@ namespace ICSharpCode.SharpDevelop.Project
protected void SetupProject(string projectFileName) protected void SetupProject(string projectFileName)
{ {
this.FileName = Path.GetFullPath(projectFileName); this.FileName = Path.GetFullPath(projectFileName);
using (MSBuildFileReader reader = new MSBuildFileReader(projectFileName)) { using (XmlTextReader reader = new XmlTextReader(projectFileName)) {
reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.WhitespaceHandling = WhitespaceHandling.Significant;
reader.Namespaces = false; reader.Namespaces = false;
reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists) reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists)
@ -110,7 +110,7 @@ namespace ICSharpCode.SharpDevelop.Project
ProjectItem.ReadItemGroup(reader, this, Items); ProjectItem.ReadItemGroup(reader, this, Items);
break; break;
case "Import": case "Import":
string import = reader.GetAttribute("Project"); string import = ProjectItem.MSBuildUnescape(reader.GetAttribute("Project"));
Imports.Add(import); Imports.Add(import);
break; break;
default: default:
@ -124,7 +124,7 @@ namespace ICSharpCode.SharpDevelop.Project
string userSettingsFileName = projectFileName + ".user"; string userSettingsFileName = projectFileName + ".user";
if (File.Exists(userSettingsFileName)) { if (File.Exists(userSettingsFileName)) {
using (MSBuildFileReader reader = new MSBuildFileReader(userSettingsFileName)) { using (XmlTextReader reader = new XmlTextReader(userSettingsFileName)) {
reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.WhitespaceHandling = WhitespaceHandling.Significant;
reader.Namespaces = false; reader.Namespaces = false;
reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists) reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists)
@ -179,7 +179,7 @@ namespace ICSharpCode.SharpDevelop.Project
Dictionary<string, PropertyGroup> configurations = isUserFile ? this.userConfigurations : this.configurations; Dictionary<string, PropertyGroup> configurations = isUserFile ? this.userConfigurations : this.configurations;
string conditionProperty = match.Result("${property}"); string conditionProperty = match.Result("${property}");
string configuration = match.Result("${value}"); string configuration = ProjectItem.MSBuildUnescape(match.Result("${value}"));
if (conditionProperty == "$(Configuration)|$(Platform)") { if (conditionProperty == "$(Configuration)|$(Platform)") {
// configuration is ok // configuration is ok
} else if (conditionProperty == "$(Configuration)") { } else if (conditionProperty == "$(Configuration)") {
@ -211,7 +211,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (!System.IO.Directory.Exists(outputDirectory)) { if (!System.IO.Directory.Exists(outputDirectory)) {
System.IO.Directory.CreateDirectory(outputDirectory); System.IO.Directory.CreateDirectory(outputDirectory);
} }
using (MSBuildFileWriter writer = new MSBuildFileWriter(fileName, Encoding.UTF8)) { using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented; writer.Formatting = Formatting.Indented;
writer.Namespaces = false; writer.Namespaces = false;
@ -267,7 +267,7 @@ namespace ICSharpCode.SharpDevelop.Project
foreach (string import in Imports) { foreach (string import in Imports) {
writer.WriteStartElement("Import"); writer.WriteStartElement("Import");
writer.WriteAttributeString("Project", import); writer.WriteAttributeString("Project", ProjectItem.MSBuildEscape(import));
writer.WriteEndElement(); writer.WriteEndElement();
} }
@ -276,7 +276,7 @@ namespace ICSharpCode.SharpDevelop.Project
string userSettingsFileName = fileName + ".user"; string userSettingsFileName = fileName + ".user";
if (userConfigurations.Count > 0 || UserBaseConfiguration.PropertyCount > 0 || File.Exists(userSettingsFileName)) { if (userConfigurations.Count > 0 || UserBaseConfiguration.PropertyCount > 0 || File.Exists(userSettingsFileName)) {
using (MSBuildFileWriter writer = new MSBuildFileWriter(userSettingsFileName, Encoding.UTF8)) { using (XmlTextWriter writer = new XmlTextWriter(userSettingsFileName, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented; writer.Formatting = Formatting.Indented;
writer.Namespaces = false; writer.Namespaces = false;
writer.WriteStartElement("Project"); writer.WriteStartElement("Project");
@ -290,7 +290,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
static void SaveProperties(MSBuildFileWriter writer, PropertyGroup baseConfiguration, Dictionary<string, PropertyGroup> configurations) static void SaveProperties(XmlWriter writer, PropertyGroup baseConfiguration, Dictionary<string, PropertyGroup> configurations)
{ {
if (baseConfiguration.PropertyCount > 0) { if (baseConfiguration.PropertyCount > 0) {
writer.WriteStartElement("PropertyGroup"); writer.WriteStartElement("PropertyGroup");
@ -304,22 +304,22 @@ namespace ICSharpCode.SharpDevelop.Project
} }
writer.WriteStartElement("PropertyGroup"); writer.WriteStartElement("PropertyGroup");
if (entry.Key.StartsWith("*|")) { if (entry.Key.StartsWith("*|")) {
writer.WriteAttributeString("Condition", " '$(Platform)' == '" + entry.Key.Substring(2) + "' "); writer.WriteAttributeString("Condition", " '$(Platform)' == '" + ProjectItem.MSBuildEscape(entry.Key.Substring(2)) + "' ");
} else if (entry.Key.EndsWith("|*")) { } else if (entry.Key.EndsWith("|*")) {
writer.WriteAttributeString("Condition", " '$(Configuration)' == '" + entry.Key.Substring(0, entry.Key.Length - 2) + "' "); writer.WriteAttributeString("Condition", " '$(Configuration)' == '" + ProjectItem.MSBuildEscape(entry.Key.Substring(0, entry.Key.Length - 2)) + "' ");
} else { } else {
writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + entry.Key + "' "); writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + ProjectItem.MSBuildEscape(entry.Key) + "' ");
} }
entry.Value.WriteProperties(writer); entry.Value.WriteProperties(writer);
writer.WriteEndElement(); writer.WriteEndElement();
} }
} }
static void SaveUnknownXmlSections(MSBuildFileWriter writer, List<string> unknownElements) static void SaveUnknownXmlSections(XmlWriter writer, List<string> unknownElements)
{ {
foreach (string element in unknownElements) { foreach (string element in unknownElements) {
// round-trip xml text again for better formatting // round-trip xml text again for better formatting
MSBuildFileReader reader = new MSBuildFileReader(new StringReader(element)); XmlTextReader reader = new XmlTextReader(new StringReader(element));
writer.WriteNode(reader, false); writer.WriteNode(reader, false);
reader.Close(); reader.Close();
} }

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

@ -161,7 +161,7 @@ namespace ICSharpCode.SharpDevelop.Project
properties[propertyName] = null; properties[propertyName] = null;
goto reLoop; goto reLoop;
} }
properties[propertyName] = reader.Value.Trim(); properties[propertyName] = ProjectItem.MSBuildUnescape(reader.Value.Trim());
} }
break; break;
} }
@ -178,7 +178,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
if (entry.Value != null) { if (entry.Value != null) {
writer.WriteValue(entry.Value); writer.WriteValue(ProjectItem.MSBuildEscape(entry.Value));
} }
writer.WriteEndElement(); writer.WriteEndElement();
} }

4
src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

@ -180,7 +180,7 @@ namespace ICSharpCode.Core
return l; return l;
} }
public void WriteProperties(XmlTextWriter writer) public void WriteProperties(XmlWriter writer)
{ {
foreach (KeyValuePair<string, object> entry in properties) { foreach (KeyValuePair<string, object> entry in properties) {
object val = entry.Value; object val = entry.Value;
@ -206,7 +206,7 @@ namespace ICSharpCode.Core
} }
} }
void WriteValue(XmlTextWriter writer, object val) void WriteValue(XmlWriter writer, object val)
{ {
if (val != null) { if (val != null) {
if (val is string) { if (val is string) {

Loading…
Cancel
Save