net 6, create console application with 'minimal template'. try add DI but BuildServiceProvider is missing. I try google about how migrate ServiceCollection but did not find nothing.
var services2 = new ServiceCollection();
var serviceProvider = services2.BuildServiceProvider();
In my idiotic case, I was using Microsoft.Extensions.DependencyInjection.Abstractions
instead of Microsoft.Extensions.DependencyInjection
. I didn't notice at first because ServiceCollection
, AddSingleton
etc were available using the first NuGet as well. Icon and author are the same for both NuGets.
The following two steps fixed it for me (VS2022, .NET Standard 2.0):
Microsoft.Extensions.DependencyInjection
. At the time of this writing, the latest version is 7.0.0
. You can use Consolidate tab in solution's Nuget Configuration page to achieve this.Microsoft.Extensions.DependencyInjection
and then re-install it (again making sure you're using the same version as other projects in the solution).Rebuild the solution after this and things should look good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With