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

Ouverte
#764 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@pcbeingused333 y travaille déjà.

Depuis le 22/11/2026.

  • #769 par @pcbeingused333 — ouverte
  • #770 par @pcbeingused333 — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
74/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
csharp, python
Domaine
build-system, cli

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
335
Forks
172
Merge moyen
6 h 54 min
PR mergées (30 j)
37

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de QuantConnect/lean-cli

Toutes les issues de QuantConnect/lean-cli

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.