Skip to content

[Feature Request]: Add property to ProjectRootElement for convenient access to <Sdk> elements #9546

Open

Description

Summary

Project files can contain <Sdk> elements (modeled by ProjectSdkElement).
For parity with other project contents, there should be a property to access only those elements (e.g. SdkReferences).

Background and Motivation

There are already properties for accessing the Sdk attribute, all properties, all imports and all items.
However, while Sdk elements appear in Children, they have no dedicated convenience accessor of their own.

Proposed Feature

/// <summary>
/// Get a read-only collection of the SDK references.
/// </summary>
public ICollection<ProjectSdkElement> Sdks => new ReadOnlyCollection<ProjectSdkElement>(Children.OfType<ProjectSdkElement>());

(name could also be SdkElements for better distinction from Sdk; there is also ChooseElements)
(using Children and not AllChildren because I assume these elements are only valid at the top level)

A nice-to-have additional property (SdkReferences) or method (GetSdkReferences()) would be one that gathers all SDK references in a project, from all sources:

  • Sdk attribute on the project
  • Sdk elements
  • Import elements that specify an SDK
    (That would make it easy for something like Dependabot to check whether a particular project references an SDK package for which an update is available.)

Alternative Designs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Feature RequestPriority:3Work that is nice to havebackloghelp wantedIssues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim.triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions