'Error "dotnet : Could not find any project in `C:\**." when running "dotnet add package Microsoft.AspNetCore.Authentication.MicrosoftAccount"

I have visual studio 2019 and i created a new asp.net core 2.2 project. now i am following these steps Configure Microsoft Account Authentication to enable external login to our web application. but when i run this command:-

dotnet add package Microsoft.AspNetCore.Authentication.MicrosoftAccount

i got this error:-

PM> dotnet add package Microsoft.AspNetCore.Authentication.MicrosoftAccount dotnet : Could not find any project in C:\Users\*****\source\repos\MSlogintest\. At line:1 char:1 + dotnet add package Microsoft.AspNetCore.Authentication.MicrosoftAccount + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Could not find ...\MSlogintest`.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Usage: dotnet add package [options]

Arguments: The project file to operate on. If a file is not specified, the command will search the current directory for one. The package reference to add.

Options: -h, --help Show command line help. -v, --version The version of the package to add. -f, --framework Add the reference only when targeting a specific framework. -n, --no-restore
Add the reference without performing restore preview and compatibility check. -s, --source The NuGet package source to use during the restore. --package-directory The directory to restore packages to. --interactive
Allows the command to stop and wait for user input or action (for example to complete authentication).

as follow:- enter image description here

and when i access the folder, i found that there is a VS project folders, as follow:- enter image description here

so why the error is saying that it can not find any project? can anyone advice on this error please? Thanks



Solution 1:[1]

I encountered the same issue and found the fix. First of all, read the error message completely and carefully. It says:

"Could not find any project ...."

Which means it was expecting the project information. If you further watch the message closely, it has mentioned the correct usage of this command i.e.

Usage: dotnet add <PROJECT> package [options] <PACKAGE_NAME>

In the argument, enter your project name and run it again. This time, you should see the success message similar to:

info : Adding PackageReference for package 'Microsoft.xxxxxxxx.xxxxxxxx' into project 'C:\Users\xxx\source\repos\ProjectFolder\xxxxxxxx.csproj'.

demonstration of the error and the fix

Solution 2:[2]

Got this working on powershell (no IDE). The solution was somewhere hidden in the comments but here is the easy one:

dotnet add <project> package <packageName>

In this case I believe it would be:

dotnet add ContosoUniversity package Microsoft.AspNetCore.Authentication.MicrosoftAccount

Solution 3:[3]

Had the same problem, when i was fiddling around with the nuget commandline it at some point proposed i should retry with elevated privileges. Specifically i tried manually pointing it one level deeper in the folder structure. (As suggested by DavidG)

I thought: okay, weird, but i am out of good ideas, so lets try that one.

Restarted as administrator, worked.

And by it worked i mean it just worked, no manual fiddling involved. I just used the graphical package manager option that just somehow became available.

So my best guess is i somehow messed up something when installing visual studio. Because i already tried just creating a new project.

Nuget option as admin

Solution 4:[4]

cd into the particular project you want to add the package to and type your dotnet command again

> cd project Directory
> dotnet add package Microsoft.AspNetCore.Authentication.MicrosoftAccount

Solution 5:[5]

You may be clicking on the wrong tab on the nuget site. Make sure you select Package Manager tab. The error you get happens when you click on the .net cli tab and use it in the package manager console window.

Solution 6:[6]

Try this in your command terminal, you should into a directory project:

dotnet add package <package.name>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Lucas Serafim
Solution 3
Solution 4 OLAWALE
Solution 5 ALAN L KOSKI
Solution 6 Ing. Misael López