Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lean/commands/library/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _add_csharp_package_to_csproj(csproj_file: Path, name: str, version: str) ->
else:
last_item_group = csproj_tree.find(".//ItemGroup[last()]")
if last_item_group is None:
last_item_group = etree.SubElement(csproj_tree.find(".//Project"), "ItemGroup")
last_item_group = etree.SubElement(csproj_tree, "ItemGroup")

last_item_group.append(etree.fromstring(f'<PackageReference Include="{name}" Version="{version}" />'))

Expand Down
2 changes: 1 addition & 1 deletion lean/components/util/library_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _add_csharp_project_to_csproj(self, csproj_file: Path, library_csproj_path:
if existing_project_reference is None:
last_item_group = csproj_tree.find(".//ItemGroup[last()]")
if last_item_group is None:
last_item_group = etree.SubElement(csproj_tree.find(".//Project"), "ItemGroup")
last_item_group = etree.SubElement(csproj_tree, "ItemGroup")

last_item_group.append(etree.fromstring(f'<ProjectReference Include="{library_csproj_path}" />'))

Expand Down
14 changes: 14 additions & 0 deletions tests/components/util/test_library_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,17 @@ def test_detects_circular_dependencies() -> None:
assert False, "Expected library_manager.add_lean_library_reference_to_project() to raise on circular dependency"
except RuntimeError:
pass


def test_add_csharp_project_to_csproj_without_item_group_adds_reference() -> None:
create_fake_lean_cli_directory()

csproj_file = Path.cwd() / "Empty.csproj"
csproj_file.write_text('<Project Sdk="Microsoft.NET.Sdk">\n <PropertyGroup />\n</Project>', encoding="utf-8")

library_manager = _create_library_manager()
library_manager._add_csharp_project_to_csproj(csproj_file, "../Library/Lib/Lib.csproj")

content = csproj_file.read_text(encoding="utf-8")
assert '<ProjectReference Include="../Library/Lib/Lib.csproj"' in content
assert content.count("<ItemGroup>") == 1
Loading