diff options
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs | 2 | ||||
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.Projects/MSBuildProjectTests.cs | 45 |
2 files changed, 46 insertions, 1 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs index de52502587..3db8b8c64a 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs @@ -929,7 +929,7 @@ namespace MonoDevelop.Projects.MSBuild } XmlUtil.Indent (format, value, false); var xmlns = value.GetAttribute ("xmlns"); - if (xmlns == Namespace) + if (xmlns == (Namespace ?? string.Empty)) value.RemoveAttribute ("xmlns"); SetProjectExtension (parent); NotifyChanged (); diff --git a/main/tests/UnitTests/MonoDevelop.Projects/MSBuildProjectTests.cs b/main/tests/UnitTests/MonoDevelop.Projects/MSBuildProjectTests.cs index ce15b478b6..2e87dee4e9 100644 --- a/main/tests/UnitTests/MonoDevelop.Projects/MSBuildProjectTests.cs +++ b/main/tests/UnitTests/MonoDevelop.Projects/MSBuildProjectTests.cs @@ -793,6 +793,51 @@ namespace MonoDevelop.Projects Assert.AreEqual (1, monoDevelopElement.ChildNodes.Count); } + [TestCase ("Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\"", + "<ExtensionData>Value</ExtensionData>", + false)] + [TestCase ("Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\"", + "<ExtensionData xmlns=\"\">Value</ExtensionData>", + false)] + [TestCase ("ToolsVersion=\"15.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"", + "<ExtensionData>Value</ExtensionData>", + true)] // xmlns='' + [TestCase ("ToolsVersion=\"15.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"", + "<ExtensionData xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">Value</ExtensionData>", + false)] + public void SetMonoDevelopProjectExtension ( + string projectElementAttributes, + string extensionXml, + bool expectedHasXmlAttribute) + { + string projectXml = + "<Project " + projectElementAttributes + ">\r\n" + + " <PropertyGroup>\r\n" + + " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + + " </PropertyGroup>\r\n" + + "</Project>"; + + var p = new MSBuildProject (); + p.LoadXml (projectXml); + + var doc = new XmlDocument (); + doc.LoadXml (extensionXml); + var element = doc.DocumentElement; + p.SetMonoDevelopProjectExtension ("Test", element); + + string xml = p.SaveToString (); + doc = new XmlDocument (); + doc.LoadXml (xml); + + var projectExtensions = (XmlElement)doc.DocumentElement.ChildNodes[1]; + var monoDevelopElement = (XmlElement)projectExtensions.ChildNodes[0]; + var propertiesElement = (XmlElement)monoDevelopElement.ChildNodes[0]; + var extensionDataElement = (XmlElement)propertiesElement.ChildNodes[0]; + + Assert.AreEqual (expectedHasXmlAttribute, extensionDataElement.HasAttribute ("xmlns")); + Assert.AreEqual ("ExtensionData", extensionDataElement.Name); + } + /// <summary> /// This works without any changes to MSBuildProperty using the full /// MSBuild xmlns value. |