Repository navigation
fix: add C# library references to a csproj that has no ItemGroup - #769
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
The parsed csproj is already the Project root, so find(".//Project")
returned None and SubElement raised. Use the root element directly.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #764
Root cause:
XMLManager.parsereturns the<Project>root element itself, socsproj_tree.find(".//Project")(which only searches descendants) returnsNonewhen the csproj has noItemGroup.etree.SubElement(None, "ItemGroup")then raisesTypeError: Argument '_parent' has incorrect type. This happened inlibrary_manager._add_csharp_project_to_csproj(after the library had already been written to the project config) and in the same pattern incommands/library/add.py.Fix: create the
ItemGroupdirectly under the parsed root. This also removes the crash for the namespaced project in the issue comment (xmlns=".../msbuild/2003"): the namespacedItemGroupis not matched by.//ItemGroup, so a newItemGroupis appended under the root, and lxml serializes it without anxmlns=""reset, so it stays in the MSBuild namespace.Test:
test_add_csharp_project_to_csproj_without_item_group_adds_referencefails on master with theTypeErrorand passes with the fix; the rest of the library tests still pass.This PR was prepared with AI assistance (Claude Code) and submitted by the account owner.