Skip to content

List package should use TargetFramework property as a key it its output instead of the effective TargetFramework; Introduce a V2 version of the list package output #14762

@nkolev92

Description

@nkolev92

The TargetFramework property has been an alias since .NET 5.
That means you could author projects with a target framework value like apple.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>apple</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFrameworkIdentifier Condition=" '$(TargetFramework)' == 'apple' ">.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion Condition=" '$(TargetFramework)' == 'apple' ">v10.0</TargetFrameworkVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGet.Configuration" Version="6.4.20" Condition=" '$(TargetFramework)' == 'apple' "/>
  </ItemGroup>

</Project>

With #5154, this is becoming even more important and pretty much necessary.

This will be a change in the table output where we'll go from say the following for a maui project to:

Project 'maui' has the following package references
   [net9.0-android35.0]:
   Top-level Package                            Requested    Resolved
   > Microsoft.Extensions.Logging.Debug         10.0.0       10.0.0
   > Microsoft.Maui.Controls                    9.0.120      9.0.120
   > Microsoft.NET.ILLink.Tasks           (A)   [9.0.12, )   9.0.12

   [net9.0-ios26.0]:
   Top-level Package                            Requested    Resolved
   > Microsoft.Extensions.Logging.Debug         10.0.0       10.0.0
   > Microsoft.Maui.Controls                    9.0.120      9.0.120
   > Microsoft.NET.ILLink.Tasks           (A)   [9.0.12, )   9.0.12

   [net9.0-maccatalyst26.0]:
   Top-level Package                            Requested    Resolved
   > Microsoft.Extensions.Logging.Debug         10.0.0       10.0.0
   > Microsoft.Maui.Controls                    9.0.120      9.0.120
   > Microsoft.NET.ILLink.Tasks           (A)   [9.0.12, )   9.0.12

   [net9.0-windows10.0.19041]:
   Top-level Package                         Requested   Resolved
   > Microsoft.Extensions.Logging.Debug      10.0.0      10.0.0
   > Microsoft.Maui.Controls                 9.0.120     9.0.120

to

Project 'maui' has the following package references
   [net9.0-android]:
   Top-level Package                            Requested    Resolved
   > Microsoft.Extensions.Logging.Debug         10.0.0       10.0.0
   > Microsoft.Maui.Controls                    9.0.120      9.0.120
   > Microsoft.NET.ILLink.Tasks           (A)   [9.0.12, )   9.0.12

   [net9.0-ios]:
   Top-level Package                            Requested    Resolved
   > Microsoft.Extensions.Logging.Debug         10.0.0       10.0.0
   > Microsoft.Maui.Controls                    9.0.120      9.0.120
   > Microsoft.NET.ILLink.Tasks           (A)   [9.0.12, )   9.0.12

   [net9.0-maccatalyst]:
   Top-level Package                            Requested    Resolved
   > Microsoft.Extensions.Logging.Debug         10.0.0       10.0.0
   > Microsoft.Maui.Controls                    9.0.120      9.0.120
   > Microsoft.NET.ILLink.Tasks           (A)   [9.0.12, )   9.0.12

   [net9.0-windows10.0.19041]:
   Top-level Package                         Requested   Resolved
   > Microsoft.Extensions.Logging.Debug      10.0.0      10.0.0
   > Microsoft.Maui.Controls                 9.0.120     9.0.120

Note that the real scenario that this enables is:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>apple;banana</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFrameworkIdentifier Condition=" '$(TargetFramework)' == 'apple' ">.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion Condition=" '$(TargetFramework)' == 'apple' ">v10.0</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFrameworkIdentifier Condition=" '$(TargetFramework)' == 'banana' ">.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion Condition=" '$(TargetFramework)' == 'banana' ">v9.0</TargetFrameworkVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGet.Configuration" Version="6.4.20" Condition=" '$(TargetFramework)' == 'apple' "/>
  </ItemGroup>

</Project>

This doesn't even work at all today.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions