Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet restore on .NET Framework project not working

Tags:

c#

.net

I have a .NET project with the following in its .csproj

<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>

When I run dotnet restore project-file.csproj I get the following:

Nothing to do. None of the projects specified contain packages to restore.

Why is this? I thought the dotnet cli could work with non Core projects too?

I have nuget packages that are referenced, so I expect the cli to go and download the nuget packages.

like image 714
J86 Avatar asked Sep 03 '19 10:09

J86


People also ask

What is the difference between NuGet restore and dotnet restore?

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.

How do I restore a NuGet project?

You can restore packages manually with nuget restore , dotnet restore , msbuild -t:restore , or through Visual Studio. The dotnet build and dotnet run commands automatically restore packages, and you can configure Visual Studio to restore packages automatically when it builds a project.

Does dotnet build do a restore?

You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new , dotnet build , dotnet run , dotnet test , dotnet publish , and dotnet pack . To disable implicit restore, use the --no-restore option.


2 Answers

dotnet cli works properly with .NET Framework only if the project was created from dotnet new command. If you create project from Visual Studio the structure of .csroj files will be different and you usually cannot run cli commands towards them

like image 180
OlegI Avatar answered Sep 21 '22 03:09

OlegI


Visual Studio only allows you to run nuget commands from nuget console (package manager console) within Visual Studio itself.

If you want to do nuget restore from command line:

  • Download nuget executable from https://www.nuget.org/downloads (it is not a installer/package, but actual executable!)

  • Save it to a folder of your choice and add it to the PATH.

  • Then, as suggested above: nuget restore solutionname.sln (but this time you don't have to run Visual Studio!)

like image 26
OverInflatedWalrus Avatar answered Sep 22 '22 03:09

OverInflatedWalrus