Reputation: 3897
How to correctly use JSON settings files in windows services build in 3.1 net core, that are published in a single file.
Upvotes: 0
Views: 458
Reputation: 3897
<ItemGroup>
<Content Update="appsettings.json">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
In your pubxml profile. Building it from the interface with: Build > Publish (Project name) will not work. You gotta use the command line from now on.
Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
To get the directory of your single-file packed exe service.
.ConfigureAppConfiguration((context, config) =>
{
config.SetBasePath(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
})
in your CreateHostBuilder
method.
I hope that this will save you some time. Ive been fighting this all morning.
Upvotes: 1