Skip to content

How can I parse PackageReference from many ItemGroup? #7522

Closed

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.

Activity

  1. added
    needs-triage
    on Apr 6, 2022
  2. rainersigwald commented on Apr 6, 2022

    @rainersigwald
    Member

    Are you wanting to do this as XML, or as MSBuild objects? The latter is preferred, but requires you to think more about the actual item type. Specifically, the Include is expressed in XML as an attribute, but becomes something more fundamental to the MSBuild type--it's not metadata because it's special and it's available in ProjectItemElement.Include. Exclude and Remove are also special.

    What specific problem are you trying to solve? There may be a better way to go about it.

  3. locked and limited conversation to collaborators on Apr 6, 2022
  4. converted this issue into a discussion #7523 on Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions