Microsoft Technologies based on the .NET software framework. Miscellaneous topics that do not fit into specific categories.
Hello hope your doing well. thanks for reaching out!
Two SDKs, Two Behaviors
-
Microsoft.NET.Sdk: Basic SDK for console apps. -
Microsoft.NET.Sdk.Worker: Designed for background services with built-in hosting. - Configuration Loading
-
Microsoft.NET.Sdk: Does not loadappsettings.jsonautomatically.-
Microsoft.NET.Sdk.Worker: Does loadappsettings.jsonby default. - Why the Difference?
- Worker SDK uses
Host.CreateApplicationBuilder()which sets up:- Configuration (including `appsettings.json`) - Logging - Dependency Injection- Basic SDK does not include this setup unless you add it manually.
- How to Fix It in
Microsoft.NET.Sdk
-
- Add this code to load configuration manually
-
var builder = Host.CreateApplicationBuilder(args); builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var app = builder.Build(); - Is It Intentional?
- Yes, it’s by design in .NET 8.
- Each SDK has different defaults based on its purpose.