DBContextOptionsBuilder does not contain a definition for ‘UseSqlServer’

Attempting to use the correct NuGet packages for your code in .Net Core can be challenging.  In this instance there is no project.json error and yet this one property is missing:

This will happen when your EF database project contains at least these two NuGet packages:

    "dependencies": {
        "Microsoft.EntityFrameworkCore": "1.1.1",
        "NETStandard.Library": "1.6.1"
    },

What’s missing is the sql server package.  It took some trial and error to find the right version:

    "dependencies": {
        "Microsoft.EntityFrameworkCore": "1.1.1",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
        "NETStandard.Library": "1.6.1"
    },

The easiest way to find the latest version of your packages is to delete from the first digit decimal to the end of the version number and type a “.”:

As you can see from the drop-down that appears, version 1.1.1 is the latest current version (by the time you read this, there could be a newer version).  When I was attempting to fix this problem, there were a lot of forums indicating that the person needed to add “using Microsoft.Data.Entity;” but that’s not the solution in this instance.

I’m posting this on my blog so I have a reference if I run into this problem again.  Hopefully this will help those who got stuck on this crazy minor issue and can’t find a working solution.

 

Leave a Reply