Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

When running dotnet list package on projects targeting older frameworks with certain package versions (e.g., netcoreapp3.1 with Microsoft.NET.Test.Sdk 18), users get an unhelpful "Sequence contains no matching element" error from NuGet. This PR adds binlog support to the restore phase to help diagnose such issues.

Changes

  • Forward binlog arguments to restore phase in PackageListCommand.cs - captures MSBuild diagnostic info when --bl or -bl:path.binlog is passed
  • Allow unmatched tokens in both PackageListCommandParser.cs and ListPackageCommandParser.cs - enables binlog args to pass through parser
  • Added test ItAcceptsBinlogArgument to verify binlog file is created during restore

Usage

dotnet list package -bl:restore.binlog

Root Cause (NuGet bug)

The actual error originates in NuGet.CommandLine.XPlat/ListPackageCommandRunner.cs line ~455:

// Transitive packages don't check for null latestVersion before calling First()
transitivePackage.LatestPackageMetadata = matchingPackage.First(p => p.Identity.Version == latestVersion);

When MeetsConstraints filters out all versions, latestVersion is null and First() throws. Top-level packages handle this correctly (lines 415-427), but transitive packages don't. This requires a fix in the NuGet.Client repository.

Original prompt

This section details on the original issue you should resolve

<issue_title>dotnet list package error Sequence contains no matching element targeting netcoreapp3.1</issue_title>
<issue_description>### Describe the bug

When dotnet list package is run in a project targeting netcoreapp3.1 and referencing Microsoft.NET.Test.Sdk 18, it fails with output Sequence contains no matching element.

To Reproduce

Create a project with the following csproj:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
  </ItemGroup>

</Project>

Ensure both .NET 10 SDK and .NET Core 3.1 SDK are installed, then run dotnet list package and observe it output Sequence contains no matching element and exit with code 1.

I've created minimal reproduction with the error demonstrated by a GitHub Action run.

Further technical details

details of dotnet --info
.NET SDK:
 Version:           10.0.100
 Commit:            b0f34d51fc
 Workload version:  10.0.100-manifests.4c0ca8ba
 MSBuild version:   18.0.2+b0f34d51f
Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/10.0.100/
.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.
Host:
  Version:      10.0.0
  Architecture: x64
  Commit:       b0f34d51fc
.NET SDKs installed:
  3.1.426 [/usr/share/dotnet/sdk]
  8.0.121 [/usr/share/dotnet/sdk]
  8.0.206 [/usr/share/dotnet/sdk]
  8.0.318 [/usr/share/dotnet/sdk]
  8.0.415 [/usr/share/dotnet/sdk]
  9.0.111 [/usr/share/dotnet/sdk]
  9.0.205 [/usr/share/dotnet/sdk]
  9.0.306 [/usr/share/dotnet/sdk]
  10.0.100 [/usr/share/dotnet/sdk]
.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.21 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
  None
Environment variables:
  DOTNET_MULTILEVEL_LOOKUP                 [0]
  DOTNET_NOLOGO                            [1]
  DOTNET_ROOT                              [/usr/share/dotnet]
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE        [1]
global.json file:
  Not found
Learn more:
  https://aka.ms/dotnet/info
Download .NET:
  https://aka.ms/dotnet/download

Thanks,
Kevin</issue_description>

<agent_instructions>I was able to reproduce using the original steps, however the command doesn't fail, it just has that output. The comment suggesting the mauilib didn't work for me because it tries to use the -f option on dotnet new.

What I first want you to do is to look into adding support for binlog generation to the dotnet list package. The binlog might be a valuable source of information. Then I want you to look into when we might want to consider FirstOrDefault() over First() in this situation, or to narrow down which line of code is failing.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dotnet list package error for netcoreapp3.1 Add binlog support to dotnet list package command Dec 2, 2025
Copilot AI requested a review from nagilson December 2, 2025 21:26
Copilot finished work on behalf of nagilson December 2, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet list package error Sequence contains no matching element targeting netcoreapp3.1

2 participants