8
votes

Generally speaking, how do we determine which NuGet package is going to contain a specific namespace.

Use case

We're changing a project so that NuGet handles most if not all of its referenced assemblies. In step one, we deleted all the references from the *.csproj file, deleted bin/, deleted the existing packages/ and packages.config, and deleted any *.dll in the project. In step two we built the project and read the error list of missing assembly references. One at a time, we're adding each missing reference using NuGet. E.g.

Install-Package Microsoft.AspNet.Mvc
Install-Package Microsoft.AspNet.Identity.Core
Install-Package EntityFramework
Install-Package Microsoft.AspNet.Identity.EntityFramework
Install-Package Microsoft.Owin
Install-Package Microsoft.AspNet.Web.Optimization
Install-Package Microsoft.AspNet.Identity.Owin
Install-Package Microsoft.Owin.Host.SystemWeb

Sometimes it's tough to determine what NuGet package to install. Other times there isn't a NuGet package and we need to add the reference the "old fashioned way".

  • System
  • System.Web
  • Microsoft.CSharp

Doing the above resolved all of the following errors. It took a while, though, and I'm wondering how to find the appropriate NuGet packages next time.

The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?)

The type or namespace name 'UserManager' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'RouteCollection' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'RequiredAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Owin' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

The type or namespace name 'IUserStore' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IOwinContext' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IdentityUser' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Display' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'DisplayAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'EmailAddress' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'EmailAddressAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'HttpPost' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'HttpPostAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IAppBuilder' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IDataProtectionProvider' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IdentityDbContext' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IdentityFactoryOptions' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'IdentityResult' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'DataTypeAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'DataType' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'ComponentModel' does not exist in the namespace 'System' (are you missing an assembly reference?)

The type or namespace name 'CompareAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)

1
A good percentage of this type of thing can be found on MSDN, usually as the top Google/Bing result for searching for the class name. For example, ActionResult tells you it's in System.Web.Mvc.dll. If you create a new dummy VS 2013 ASP.NET project, you'll get a ludicrous number of default NuGet packages, so you can dig through those directories, and there's a good chance you'll find one that has the DLL you're looking for.Joe Enos
ReSharper helps with this: jetbrains.com/resharper/help/…Big McLargeHuge

1 Answers

5
votes

Simply put, there is no way to know... since there's no requirement that a NuGet package publish or mention its namespaces. On top of that, namespaces can exist across multiple assemblies, which means the same namespace can exist in multiple NuGet packages (particularly if you don't know which version you need).

For instance, just because my NuGet package has System.Web.MVC doesn't mean it has the dependencies you are looking for.

Basically, you have to know which packages you need. That's what the packages.conf file is for. By deleting that, you removed the information you needed to know which assemblies and versions were required.