Use HttpClientFactory from .NET 4.6.2

All of the Microsoft.Extensions.* packages target .NET Standard 2.0. That means that you can use Dependency Injection, Configuration, Logging and HttpClientFactory if you add the appropriate package to your application. You need to add Microsoft.Extensions.Http to use HttpClientFactory and Microsoft.Extensions.Http.Polly if you want to use it with Polly To configure HttpClientFactory you’ll have to add … Read more

Visual studio 2017 Update 3 – The SDK ‘Microsoft.NET.Sdk.Web’ specified could not be found

I stumbled upon this issue a number of times recently. Here’s a brief list of the workaround I found (one of them always worked until now): Install the right .NET Core SDK: Either the latest version or the version required by your project. Clean-up obsolete .NET Core versions: Go to Control Panel and uninstall previous … Read more

How to get “Manage User Secrets” in a .NET Core console-application?

“Manage user secrets” from a right click is only available in web projects. There is a slightly different process for console applications It requires manually typing the required elements into your csproj file then adding secrets through the PMC I have outlined the process that worked for me in my current project step by step … Read more

Should HttpClient instances created by HttpClientFactory be disposed?

Calling the Dispose method is not required but you can still call it if you need for some reasons. Proof: HttpClient and lifetime management Disposal of the client isn’t required. Disposal cancels outgoing requests and guarantees the given HttpClient instance can’t be used after calling Dispose. IHttpClientFactory tracks and disposes resources used by HttpClient instances. … Read more

Copy all dependencies from .Net Standard libraries to .Net Framework Console application

After going through an article by Scott Hanselman, below solution worked like a charm. “Using .NET Standard requires you to use PackageReference to eliminate the pain of “lots of packages” as well as properly handle transitive dependencies. While you may be able to use .NET Standard without PackageReference, I wouldn’t recommend it.” Add below line … Read more

Compile a .NET Core application as an EXE file using Visual Studio 2017

Update 2019: .NET Core 3.0+ projects will now include an executable for the platform you build on by default. This is just a shim executable and your main logic is still inside a .dll file. But .NET Core 3.0 also introduced single-file deployments so deploying with dotnet publish -r win-x64 -p:PublishSingleFile=True –self-contained false will create … Read more

Compatibility shim used by .NET Standard 2.0

This works by creating all the necessary libraries that are referenced by classic .NET libraries. E.g. in .NET Core the implementation of Object or Attribute is defined in System.Runtime. When you compile code, the generated code always references the assembly and the type => [System.Runtime]System.Object. Classic .NET projects however reference System.Object from mscorlib. When trying … Read more