-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with reading appsettings file using Host.CreateDefaultBuilder #3
Comments
@valeriob According to Host ASP.NET Core in a Windows Service on Microsoft Docs, It does state, however, that loading the app's default settings files - Does it make any difference if you call Alternatively, you might workaround this issue by calling:
|
Hi, you can replace CreateHostBuilder(args)
// set base path for application
.UseContentRoot(Path.GetDirectoryName(Process
.GetCurrentProcess()
.MainModule.FileName))
.RunAsTopshelfService(); |
The only solution worked is the same as used in UseWindowsService() extension: var rc = CreateHostBuilder(args)
.UseContentRoot(AppContext.BaseDirectory)
.RunAsTopshelfService(); |
Thank you soooooooooo much |
Creating a default host builder via this api
var builder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
it does not load appsettings.json settings.
This is due to CreateDefaultBuilder setting the content root to
builder.UseContentRoot(Directory.GetCurrentDirectory());
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.0
and at that time GetCurrentDirectory is c:\windows\system32
The text was updated successfully, but these errors were encountered: