I have this structure of solutions and projects:
projects
|--.nuget
| |--packages.config
|
|--projFolderA
| |--projectA.csproj
|
|--projFolderB
| |--projectB.csproj
|
|--projFolderC
| |--projectC.csproj
|
|--solutionAB.sln
|--solutionBC.sln
|--solutionCA.sln
Each solution is configured to use some libraries using nuget. Now, when I run:nuget restore
, I got this error: This folder contains more than one solution file.
But if I open each solution in VS2013 then it's fine.
This is the nuget settings in each of my *.sln file:
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{334B5D1D-8694-472B-8170-3D36A395DCEF}"
ProjectSection(SolutionItems) = preProject
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
What did I do wrong ? How can I run nuget restore
from console in this case ?
Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.
Restore by using MSBuild You can use msbuild -t:restore to restore packages in NuGet 4. x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher. This command restores packages in projects that use PackageReference for package references.
To do that, go to Tools, NuGet Packaged Manager, then go to Package Manager Settings. Go to the General section, and then make sure you have a checkmark for Allow NuGet to download missing packages and also to automatically check for missing packages during the build in Visual Studio. So click on OK.
nuget restore will ensure all of your NuGet dependencies are downloaded and available to your project. Whereas dotnet restore is a complete restoration of all NuGet dependencies as well as references and project specific tools. Meaning that if you run nuget restore , you are only restoring NuGet packages.
Try nuget restore solutionABC.sln
See https://docs.nuget.org/consume/command-line-reference
See bolded section below as to why you get the error.
Restore Command Notes
The restore command is executed in the following steps:
Determine the operation mode of the restore command.
If packages.config file is specified, nuget restores packages listed in the packages.config file.
If solution is specified, nuget restores packages for the solution's projects. In this case, nuget needs to locate the solution file.
If solution is a file, that file is used as the solution file.
If solution is a directory, then nuget searches for a *.sln file in that directory. If exactly one file is found, that file is used as the solution file. Otherwise, nuget displays an error message and exits.
If no argument is provided, nuget first looks for solution files in the current directory. If there is just one solution file, nuget will restore packages for that solution. If there are multiple solution files, an error message is displayed and nuget exits.
If there are no solution files, nuget then searches for the packages.config file in the current directory. If the file exists, nuget will restore packages listed in the packages.config file.
If there are no solution files and no packages.config file in the current directory, an error message is displayed and nuget exits.
If the operation mode is restoring for a solution, then -SolutionDirectory option is not applicable. In this case, nuget displays an error message and exits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With