An accurate depiction of a NuGet package factory

Solving: ‘DbContextOptionsBuilder’ does not contain a definition for ‘UseSqlServer’

Reading Time: 2 minutes.

This is another, kind of a classic and simple solution to a fairly simple problem: how to fix it, when your DbContextOptionsBuilder fails to take in your connection string and complains about UseSeqlServer ?

So, let’s set the scene. You’re building your DbContext (called ApplicationDbContext in the example below) in a .NET Core application of some sorts. You’ll do this like shown below:

using Microsoft.EntityFrameworkCore;
using System;
namespace YourNamespace
    public class YourClass
        private string _connectionString = "This comes from your configuration file";
        public YourClass()
           var options = new DbContextOptionsBuilder<ApplicationDbContext>()
            using (var ctx = new ApplicationDbContext(options))
               // Your code here

If you want to learn more about building a DbContext, see this article:

However, your code fails to build with an error like below:

Error CS1061 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?)

What do?


The solution is usually fairly simple. You’re just missing a nuget package: Microsoft.EntityFrameworkCore.SqlServer

That’s typically a simple fix. Either use NuGet Package Manager, or run this in the console:

Install-Package Microsoft.EntityFrameworkCore.SqlServer

However, for whatever reason, that doesn’t always work. I’ve had the package manager fail silently and the Package Manager console command above never finish.

In that case, you can always just edit your nuget configuration file, or if you’re on .NET Core, by editing the project file like shown below:

And then, add the line for the package like shown below (your required version might not be 3.0.0, though – compare to packages like Microsoft.EntityFrameworkCore to figure out the desired version)!

<Project Sdk="Microsoft.NET.Sdk">
    <!-- You'll probably have quite a few other nuget packages right around here  ... :D -->
    <!-- Add the line below: -->
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />

Next: save, and then restore the packages:

After a while (after it’s finished restoring), you should be able to build/package your solution again!


Leave a Reply

6 Comment threads
7 Thread replies
Most reacted comment
Hottest comment thread
7 Comment authors
SweetyNader SaoudyPedro FelipeZaulomm Recent comment authors
Notify of
Suchi Siwach
Suchi Siwach

Thank you for sharing this article.

Sylvain Gantois
Sylvain Gantois

Hi, thanks, this put me on the right track. Since it is changing all the time, there is now a
Microsoft.EntityFrameworkCore.SqlServer nuget package. Cheers.


Graicas Muchas gracias

Pedro Felipe
Pedro Felipe

Do u know the rason why the EntityFrameworkCore.SqlServer don’t install together with EntityFrameworkCore when we install it?

Nader Saoudy
Nader Saoudy