Skip to content

Commit

Permalink
fix: Support for both classic-style and SDK-style csproj
Browse files Browse the repository at this point in the history
  • Loading branch information
mezum committed Nov 23, 2024
1 parent 0f87862 commit 6cd118d
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ public override string OnGeneratedCSProject(string path, string content)

var baseDir = Path.GetDirectoryName(path);
var xDoc = XDocument.Parse(content);
var projectE = xDoc.Element("Project");
var nsMsbuild = (XNamespace)"http://schemas.microsoft.com/developer/msbuild/2003";
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)
{
Expand All @@ -153,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("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("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)
Expand Down

0 comments on commit 6cd118d

Please sign in to comment.