Skip to content

How can I parse PackageReference from many ItemGroup? #7522

@6a6f6a6f

Description

@6a6f6a6f

I'm using Microsoft.Build on version 17.1.0 as a library inside a .NET 6 simple application. My main goal is to have the attributes of PackageReference (Include and Version) starting at ProjectRootElement.Open(path), but when I loop thou the ItemGroups, I'm not able to find any other attribute than Version:

project.ItemGroups
    .SelectMany(rootElement => rootElement.Items)
    .Where(itemElement => itemElement.ElementName == "PackageReference")
    .ToList()
    .ForEach(item =>
    {
        var metadata = item.Metadata.ToList();
        metadata.ForEach(d =>
        {
            Console.WriteLine($"{d.Name}: {d.Value}");
        });
    });

If these questions do not fit here, please bring me some direction.

Many thanks for considering my request.

Information about my runtime:

  • .NET SDK: 6.0.201 (commit ef40e6aa06);
  • OS Name: Mac OS X;
  • OS Version: 12.2;
  • OS Platform: Darwin;
  • RID: osx.12-arm64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageHave yet to determine what bucket this goes in.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions