Visual Studio C# does not allow me to use Microsoft.AspNet.Identity namespace

徘徊边缘 提交于 2019-12-12 03:46:25

问题


Why is my application not letting me use the following namespace:

 using Microsoft.AspNet.Identity;

Is there any way I can get rid of this in Visual Studio 2015?


回答1:


While the other answers here are correct in explaining how to fix this issue, they don't really understand what you're doing or why it's necessary.

The libraries that get referenced by default do not include types in the Microsoft.AspNet.Identity namespace. So you need to reference an assembly that contains that in order to actually be able to use it in your code (and make your using statement work).

In .NET, there's two common ways to add references to assemblies that don't come included.

You can download a .dll file to your computer, then right click your project or references node in Solution Explorer and browse to where you downloaded the file. However, this "loose DLL" approach has some downsides. You've got to manually find the DLL's. You have to repeat the process if you want to get an updated version of the assembly. And it's hard to know when an updated assembly is available, or where to go to find the assembly.

A better solution is to use NuGet to bring in external assemblies. NuGet is a "package manager". It's an easy way to install assemblies from a centralized repository. There is a public NuGet repository at nuget.org where most members of the .NET community upload their useful assemblies for others to use. And indeed, Microsoft publishes an package Microsoft.AspNet.Identity.Core that contains an assembly that contains types in the Microsoft.AspNet.Identity namespace.

You can install this NuGet package to your project by opening the Solution Explorer, right clicking your project, clicking Manage NuGet Packages, finding the Microsoft.AspNet.Identity.Core package and clicking install (this is also where you can go to see if you have package updates available and to install them). Alternatively, you can open up the Package Manager Console (Tools> NuGet Package Manager> Package Manager Console) and then executing the following command

Install-Package Microsoft.AspNet.Identity.Core

You can use this knowledge to install a great number of useful libraries into your application. NuGet.org has over 65,000 packages in their repository.




回答2:


I didn't have the NuGet Package installed. For this, (In Visual Studio) I went to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution and installed the Microsoft.AspNet.Identity.Core package.

For anyone using new packages and namespaces for the first time, like I was, don't despair. It's not as complicated as it seems!




回答3:


You need a reference to Microsoft.AspNet.Identity.Core. You can get this via NuGet from:

https://www.nuget.org/packages/Microsoft.AspNet.Identity.Core/

Essentially in your Package Manager Console you need to use the following command:

Install-Package Microsoft.AspNet.Identity.Core



回答4:


install package from nuget Install-Package Microsoft.AspNet.Identity.Core

VS2015 Tools>Nuget Package Manager>Package Manager Console

PM> Install-Package Microsoft.AspNet.Identity.Core press Enter

Then using Microsoft.AspNet.Identity; add a using statement in your .cs page




回答5:


Microsoft has not supplied all the references in Visual Studio 2015. For Getting rid of the mentioned problem, to install Microsoft ASP.NET Identity Core, run the following command in the Package Manager Console

Install-Package Microsoft.AspNet.Identity.Core

For more information refer to here.



来源:https://stackoverflow.com/questions/40511114/visual-studio-c-sharp-does-not-allow-me-to-use-microsoft-aspnet-identity-namespa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!