0

In some projects I need to add NuGet package Microsoft.Data.SqlClient to the project before I can do

using Microsoft.Data.SqlClient

In other projects, I can do that without explicitly adding the NuGet package. The examples below are both .NET 6.0 projects (same for .NET 5).

Referenced directly: Nuget Microsoft.Data.SqlClient required

Not referenced directly: Nuget Microsoft.Data.SqlClient not required

I am wondering how this works. Is the package referenced indirectly somehow?

Sha
  • 2,185
  • 1
  • 36
  • 61
  • Doh, I actually see `AspNetCore.HealthChecks.SqlServer` has dependency on `Microsoft.Data.SqlClient` – Sha Dec 06 '21 at 18:46
  • No, you can't ignore the NuGet package. `Microsoft.Data.SqlClient` is a new driver, only available as a NuGet package. It was never included in the .NET SDK and not meant to be. That's why the name changed from `System.Data.SqlClient` to `Microsoft.Data.SqlClient`. The package has to be referenced either directly or indirectly. – Panagiotis Kanavos Dec 06 '21 at 18:46
  • BTW Microsoft.Data.SqlClient was released recently so you probably shouldn't depend on the minimum version referenced by another package. – Panagiotis Kanavos Dec 06 '21 at 18:48
  • @PanagiotisKanavos - well, it shows that you don't have to add the NuGet yourself. It can be indirectly referenced via another NuGet. In my case, Microsoft.Data.SqlClient is referenced by AspNetCore.HealthChecks.SqlServer – Sha Dec 06 '21 at 18:53

1 Answers1

3

AspNetCore.HealthChecks.SqlServer depends on Microsoft.Data.SqlClient:

  • .NETStandard 2.0
    • Microsoft.Data.SqlClient (>= 2.1.2)
    • Microsoft.Extensions.Diagnostics.HealthChecks (>= 5.0.1)
  • net5.0
    • Microsoft.Data.SqlClient (>= 2.1.2)
    • Microsoft.Extensions.Diagnostics.HealthChecks (>= 5.0.1)

so as transitive dependency Microsoft.Data.SqlClient becomes available for you also.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132