Skip to content

fix: add C# references outside conditional ItemGroups - #770

Open
pcbeingused333 wants to merge 2 commits into
QuantConnect:masterfrom
pcbeingused333:fix/csproj-conditional-itemgroup
Open

pcbeingused333 wants to merge 2 commits into
QuantConnect:masterfrom
pcbeingused333:fix/csproj-conditional-itemgroup

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #767
Fixes #764

Adding the first C# library reference can fail when a project file has no ItemGroup because the fallback searches for a nested Project even though the parsed element is already the Project root. Appending to the last descendant ItemGroup can also put references inside a conditional group or a Target.

Both project and NuGet package references now use the last unconditional ItemGroup directly under the Project root, creating one if needed. The lookup and insertion use the Project namespace, so repeated adds reuse the existing reference in MSBuild files that use either a default namespace or a prefix.

The library manager and library command suites passed all 76 tests. Regression coverage includes the missing ItemGroup case from #769 and both namespace forms, with repeated project adds and package version updates.

This change was prepared with AI assistance.

lean library add appended the reference to the last ItemGroup. A Condition
on that group made the library available only in that configuration.
Project and package references now use a project ItemGroup with no
Condition, or a new one when every group is conditional.
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

This PR now includes the regression from #769 for a project with no ItemGroup, along with coverage for default and prefixed MSBuild namespaces. Could you review both callers of the shared ItemGroup helper together, especially how the project-reference and NuGet-package paths handle existing references? The library manager and library command suites passed all 76 tests.

This comment was drafted with Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a C# library can silently restrict its reference to Debug builds Adding the first C# library reference fails when the project has no ItemGroup

1 participant