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

Abierto
#764 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@pcbeingused333 ya está trabajando en esto.

Desde el 22/11/2026.

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

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp, python
Área
build-system, cli

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
335
Forks
172
Merge medio
6 h 54 min
PR fusionados (30 d)
37

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de QuantConnect/lean-cli

Todos los issues de QuantConnect/lean-cli

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.