0
votes

Im trying to follow a Entity Framework Core video in a .NET Core 2.1 DAL class library. In the DbContext.OnCofiguring the following code is placed :

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);

        optionsBuilder.UseSqlServer("Server*.");
    }

The problem is that the UseSQLServer is missing? From this its suggested to add Microsoft.EntityFrameworkCore.SqlServer nuget. When doing this I get some version conflicts that I dont know how to solve :

Severity Code Description Project File Line Suppression State 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?) DataAccessLayer

--

Severity Code Description Project File Line Suppression State Error Package restore failed. Rolling back package changes for 'DataAccessLayer'.

--

Severity Code Description Project File Line Suppression State Error NU1605 Detected package downgrade: Microsoft.Extensions.Configuration from 2.2.0 to 2.1.1. Reference the package directly from the project to select a different version.
DataAccessLayer -> Microsoft.EntityFrameworkCore.SqlServer 2.2.3 -> Microsoft.EntityFrameworkCore.Relational 2.2.3 -> Microsoft.EntityFrameworkCore 2.2.3 -> Microsoft.Extensions.Logging 2.2.0 -> Microsoft.Extensions.Configuration.Binder 2.2.0 -> Microsoft.Extensions.Configuration (>= 2.2.0) DataAccessLayer -> Microsoft.Extensions.Configuration (>= 2.1.1) DataAccessLayer

--

Severity Code Description Project File Line Suppression State Error NU1605 Detected package downgrade: Microsoft.Extensions.DependencyInjection from 2.2.0 to 2.1.1. Reference the package directly from the project to select a different version. DataAccessLayer -> Microsoft.EntityFrameworkCore.SqlServer 2.2.3 -> Microsoft.EntityFrameworkCore.Relational 2.2.3 -> Microsoft.EntityFrameworkCore 2.2.3 -> Microsoft.Extensions.DependencyInjection (>= 2.2.0) DataAccessLayer -> Microsoft.Extensions.DependencyInjection (>= 2.1.1) DataAccessLayer

--

I suspect that the project is using a couple of nuget packages and some of them is referencing a diffrent version of another nuget or dll.

It suggest to reference a package direcly? Does this mean that I should reference a dll manually? Where do I get the dll from?

1

1 Answers

0
votes

The default severity for NU1605 is warning and since you're seeing it as an error, it means that your project has opt-in'ed into treating errors as warnings.

The reason for the package downgrade is probably due to NuGet's nearest-wins rule. The only way to avoid a downgrade is to add a PackageReference to the downgraded package to your project, that way the version you select is always nearest and transient dependencies can never downgrade it.

Otherwise you stop shooting yourself in the foot by either turning off "treat all warnings as errors" and list only the specific warnings you want treated as errors. Or, add NU1605 to the list of warnings to suppress (<NoWarn> in the csproj).