dotnet/msbuild

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

Open

#9,546 创建于 2023年12月14日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)C# (5,062 star) (1,364 fork)batch import
Feature RequestPriority:3backloghelp wantedtriaged

描述

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

贡献者指南