I'm trying to publish my .NET 7 Web API on Azure as App Service + Database. Locally I execute the following code to get appsettings.json working in my dotnet publish (-ed) app:
var builder = WebApplication.CreateBuilder(args);
builder.Configuration
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "src", "Web"))
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
.Build();
For some reason otherwise it only works in IDE and won't work in dotnet publish'ed app.
But on the Azure I get:
Unhandled exception. System.IO.DirectoryNotFoundException: /home/site/wwwroot/src/Web/
2023-04-13T12:29:00.959798795Z at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
2023-04-13T12:29:00.959811695Z at Microsoft.Extensions.Configuration.FileConfigurationExtensions.SetBasePath(IConfigurationBuilder builder, String basePath)
2023-04-13T12:29:00.966010289Z at Program.<Main>$(String[] args) in /home/runner/work/flitch-backend/flitch-backend/src/Web/Program.cs:line 14
2023-04-13T12:29:04.369525714Z /opt/startup/startup.sh: line 17: 69 Aborted (core dumped) dotnet Web.dll
I think the problem might be in the folder structure, my folder structure is like that:
Application Application/src Application/src/Web (the project I run and the directory where appsettings.json reside)
Here's the github repo of the project I try to publish: https://github.com/Rostand-Corp/flitch-backend/tree/develop
appsettings.json properties are: Build action: Content Copy to output directory: Copy always
I have tried changing changing path to just current directory, but it won't work