diff --git a/src/CsprojModifier/Assets/CsprojModifier/Editor/Features/InsertAdditionalImportFeature.cs b/src/CsprojModifier/Assets/CsprojModifier/Editor/Features/InsertAdditionalImportFeature.cs index c1827cf..3be17dc 100644 --- a/src/CsprojModifier/Assets/CsprojModifier/Editor/Features/InsertAdditionalImportFeature.cs +++ b/src/CsprojModifier/Assets/CsprojModifier/Editor/Features/InsertAdditionalImportFeature.cs @@ -145,7 +145,12 @@ public override string OnGeneratedCSProject(string path, string content) var baseDir = Path.GetDirectoryName(path); var xDoc = XDocument.Parse(content); var nsMsbuild = (XNamespace)"http://schemas.microsoft.com/developer/msbuild/2003"; - var projectE = xDoc.Element(nsMsbuild + "Project"); + var projectE = xDoc.Element(nsMsbuild + "Project") ?? xDoc.Element("Project"); + if (projectE == null) + { + throw new Exception($"Unknown csproj format: {path}"); + } + var projectNs = projectE.GetDefaultNamespace(); foreach (var target in settings.AdditionalImports) { @@ -154,11 +159,11 @@ public override string OnGeneratedCSProject(string path, string content) if (target.Position == ImportProjectPosition.Append) { projectE.Add(new XComment($"{target.Path}:{hash}")); - projectE.Add(new XElement(nsMsbuild + "Import", new XAttribute("Project", target.Path))); + projectE.Add(new XElement(projectNs + "Import", new XAttribute("Project", target.Path))); } else if (target.Position == ImportProjectPosition.Prepend) { - projectE.AddFirst(new XElement(nsMsbuild + "Import", new XAttribute("Project", target.Path))); + projectE.AddFirst(new XElement(projectNs + "Import", new XAttribute("Project", target.Path))); projectE.AddFirst(new XComment($"{target.Path}:{hash}")); } else if (target.Position == ImportProjectPosition.AppendContent)