Skip to content

Commit

Permalink
Merge pull request #20 from mezum/fix-issue-12
Browse files Browse the repository at this point in the history
fix: Add support for both classic and SDK-style csproj formats
  • Loading branch information
mayuki authored Nov 26, 2024
2 parents 8887279 + 6cd118d commit 2e6a73d
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit 2e6a73d

Please sign in to comment.