Home > Back-end >  Find package for extension method?
Find package for extension method?

Time:07-28

I have two solutions. Both call extension method "AddDbContext" on an object of type IServiceCollection. Both solutions are .NET 5.

It works fine in one project, but the other project doesn't know about the extension method. Is there an easy way to determine which Nuget package I need to install? Short of Googling (which I can do), is there a simple way in Visual Studio to determine which package contains the extension method?

In the working solution I right click on the call to "AddDbContext" and go to definition. It's in namespace "Microsoft.Extensions.DependencyInjection" in file EntityFrameworkServiceCollectionExtensions.cs. Both solutions have package Microsoft.Extensions.DependencyInjection version 5.0.2 installed on the only project.

The solutions don't have all the same packages installed, but from their names I can't decipher which package installed might be adding IServiceCollection.AddDbContext.

I can Google this, of course, I just wonder if there is some menu in Visual Studio which can just tell me which package contains the extension method?

In this particular case, installing package Microsoft.EntityFrameworkCore v5.0.10 fixed the issue. But why was that package needed, and how could I have determined that using Visual Studio?

CodePudding user response:

If you choose "Peek definition" instead of "Go to definition", then you see the full path of the assembly inside the region at the top of the definition. In the path you see what package it is from.

Some decompiler extensions (such as ILSpy or dotPeek) might also show it in the "Go to definition" view.

  • Related