Adding the first C# library reference fails when the project has no ItemGroup

Aberta
#764 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@pcbeingused333 já está trabalhando nisso.

Desde 22/11/2026.

  • #769 de @pcbeingused333 — aberto
  • #770 de @pcbeingused333 — aberto

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
74/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
csharp, python
Domínio
build-system, cli

Direção de pesquisa

Start by reading LibraryManager._add_csharp_project_to_csproj and _add_csharp_package_to_csproj in lean/commands/library/add.py, then find the existing tests for C# library and NuGet insertion. Reproduce with a valid SDK style .csproj containing no ItemGroup and run the relevant tests. Done means both insertion paths create the first ItemGroup on the project root and the regression case passes.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

priority:P2

Problem

Adding a Lean C# library fails when the consuming .csproj has no ItemGroup. The library is nevertheless recorded in config.json, so repeating the command reports that it is already added while the .csproj still has no ProjectReference.

Reproduced on master at 3842533.

Reproduction

  1. In an initialized Lean CLI directory, have C# projects App and Library/Lib.

  2. Give App/App.csproj this valid SDK-style content:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net10.0</TargetFramework>
      </PropertyGroup>
    </Project>
    
  3. Run lean library add App Library/Lib --no-local.

Observed: exit 1 with Argument '_parent' has incorrect type (expected lxml.etree._Element, got NoneType).

  1. Run the same command again.

Observed: exit 0 and Library Lib has already been added to the project App, but App.csproj still has no ProjectReference.

Cause and expected result

LibraryManager._add_csharp_project_to_csproj tries to create the first ItemGroup beneath csproj_tree.find(".//Project"). The parsed tree is already the Project element, so that descendant lookup returns None. _add_csharp_package_to_csproj in lean/commands/library/add.py contains the same insertion pattern.

Adding the first library reference should create the necessary ItemGroup on the project root and succeed for a valid project without one. Add regression coverage for this minimal .csproj case. Suggestion: reuse the correct root-insertion handling for both C# library-reference and NuGet-package insertion.

Impact is limited to projects without an existing ItemGroup; retaining an empty <ItemGroup /> before the first add avoids the crash.

Linguagem predominante
Python
Estrelas
335
Forks
172
Merge médio
6h 54min
PRs com merge (30d)
37

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de QuantConnect/lean-cli

Todas as issues de QuantConnect/lean-cli

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.