Skip to content

nuget.exe restore -MSBuildPath crashes when pointing it to .NET SDK directory #14844

@agr

Description

@agr

NuGet Product Used

NuGet.exe

Product Version

7.3.0

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

mkdir msbuild-repro
cd msbuild-repro
dotnet new sln --format sln
dotnet new console
dotnet add package newtonsoft.json
dotnet sln msbuild-repro.sln add msbuild-repro.csproj

nuget.exe restore msbuild-repro.sln -MSBuildPath "C:\Program Files\dotnet\sdk\10.0.201" -verbosity detailed

You might need to replace C:\Program Files\dotnet\sdk\10.0.201 path with something more relevant to the computer you'd be running it on.

Some better error message would be nice.

Verbose Logs

> nuget.exe restore msbuild-repro.sln -MSBuildPath "C:\Program Files\dotnet\sdk\10.0.201" -verbosity detailed
Using Msbuild from 'C:\Program Files\dotnet\sdk\10.0.201'.
NuGet Version: 7.3.0.70
Error parsing solution file at ...\msbuild-repro\msbuild-repro.sln: Object reference not set to an instance of an object.
  Object reference not set to an instance of an object.
NuGet.Commands.CommandException: Error parsing solution file at ...\msbuild-repro\msbuild-repro.sln: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at NuGet.Common.Solution.LoadSolutionWithMsbuild14(Assembly msbuildAssembly, String solutionFileName)
   at NuGet.Common.Solution..ctor(String solutionFileName, String msbuildPath)
   at NuGet.CommandLine.MsBuildUtility.GetAllProjectFileNamesWithMsBuild(String solutionFile, String msbuildPath)
   --- End of inner exception stack trace ---
   at NuGet.CommandLine.MsBuildUtility.GetAllProjectFileNamesWithMsBuild(String solutionFile, String msbuildPath)
   at NuGet.CommandLine.RestoreCommand.ProcessSolutionFile(String solutionFileFullPath, PackageRestoreInputs restoreInputs)
   at NuGet.CommandLine.RestoreCommand.<DetermineRestoreInputsAsync>d__65.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.RestoreCommand.<ExecuteCommandAsync>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args, IEnvironmentVariableReader environmentVariableReader)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area:ErrorHandlingwarnings and errors/log messages & related error codes.Priority:3Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog.Product:NuGet.exeNuGet.exeType:Bug

    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