Share via

Should the ApplicationBuilder behave differently between Microsoft.NET.Sdk and Microsoft.NET.Sdk.Worker??

Alastair Davie 6 Reputation points
2025-10-30T23:22:24.5433333+00:00

I've noticed if my project file references Microsoft.NET.Sdk, then the ApplicationBuilder does NOT automatically load the appsettings.json file, but if the project file references Microsoft.NET.Sdk.Worker, then it does.

I've noticed this has occurred while creating an application in .NET 8.0.
It does feel like an important change in behaviour with a very subtle difference.

Is it intentional?

Thoughts???

Developer technologies | .NET | Other
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-10-31T05:30:31.2133333+00:00

    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 load appsettings.json automatically.
      • Microsoft.NET.Sdk.Worker: Does load appsettings.json by 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.

     

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.