NuGet/Home

NullReferenceException during list package in NuGet.CommandLine.XPlat

Open

#13,397 创建于 2024年4月17日

在 GitHub 查看
 (14 评论) (1 反应) (0 负责人)HTML (1,459 star) (292 fork)batch import
Functionality:ListPackagePriority:3Product:dotnet.exeStyle:PackageReferenceType:Bughelp wanted

描述

NuGet Product Used

dotnet.exe

Product Version

8.0.204

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

This issue has already been created in .NET SDK, but was closed There with the hint that It's more likely to be a NuGet issue.

Describe the bug

When I run dotnet list package for a solution where

a) Non-project MsBuild-Properties are used, e.g. SolutionDir b) Directories are not defaulted, e.g. BaseIntermediateOutputPath

the command exits with an error, saying that

  • A file/directory cannot be found files, as $(SolutionDir) resolves to an empty string and hence is rooted erroneously
  • The project.assets.json cannot be found, as it is not stored in $(MSBuildProjectDirectory)obj\

In our solution we have > 200 projects. These projects use a common base intermediate output path set to $(SolutionDir)obj\$(MSBuildProjectName)\ as it makes it easier to reset the files.

To Reproduce

An example can be found at this gist

Expected output

$ dotnet list package --outdated

The following sources were used:
   https://api.nuget.org/v3/index.json
   C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Project `sample` has the following updates to its packages
   [net8.0]:
   Top-level Package      Requested   Resolved   Latest
   > Grpc.Tools           [2.51.0]    2.51.0     2.62.0

Actual output

$ dotnet list package --outdated
 dotnet list package --outdated

The following sources were used:
   https://api.nuget.org/v3/index.json
   C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

No assets file was found for `C:\myprojects\temp\dotnet-sdk-tests\test-projects\sample\sample.csproj`. Please run restore before running this command.

Diagnostic output is not helpful:

$ dotnet list package --outdated -v diag 

The following sources were used:
   https://api.nuget.org/v3/index.json
   C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

No assets file was found for `C:\myprojects\temp\dotnet-sdk-tests\test-projects\sample\sample.csproj`. Please run restore before running this command.

Workarounds

None applicable. From my point of view, it would be applicable to pass MsBuildVarialbles to dotnet list package, e.g.

$ dotnet list package --outdated -p:SolutionDir=${PWD} -p:BaseIntermediateOutputPath='$(SolutionDir)obj\$(MSBuildProjectName)'

Exceptions (if any)

No exception to be found.

Further technical details

$ dotnet --info
.NET SDK:
 Version:           8.0.204
 Commit:            c338c7548c
 Workload version:  8.0.200-manifests.7d36c14f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.204\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.4
  Architecture: x64
  Commit:       2d7eea2529

.NET SDKs installed:
  6.0.129 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]
  6.0.321 [C:\Program Files\dotnet\sdk]
  6.0.421 [C:\Program Files\dotnet\sdk]
  7.0.408 [C:\Program Files\dotnet\sdk]
  8.0.104 [C:\Program Files\dotnet\sdk]
  8.0.204 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  • VS Code 1.88.1

Verbose Logs

$ dotnet list package --outdated -v diag 

The following sources were used:
   https://api.nuget.org/v3/index.json
   C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

No assets file was found for `C:\myprojects\temp\dotnet-sdk-tests\test-projects\sample\sample.csproj`. Please run restore before running this command.

贡献者指南