Как получить доступ к content root path?

Необходимо передать в c.SetBasePath, contentRootPath как это сделать? Знаю что есть доступ через свойство IHostEnvironment.ContentRootPath, но не понимаю как правильно к нему обратиться.

private static async Task Main(string[] args)
    {
        var host = Host
            .CreateDefaultBuilder()
            .ConfigureServices(Configure)
            .ConfigureAppConfiguration(c =>
            {
               //c.SetBasePath(IHostEnvironment.ContentRootPath)
                c.AddEnvironmentVariables();
                c.AddJsonFile("appsettings.json");
            })
            .UseConsoleAppFramework(args)
            .ConfigureLogging(x =>
            {
                x.ClearProviders();
                x.AddSacmSerilog(true);
            })
            .Build();

        await host.Services.InitializeEfCore();

        await host.RunAsync();
    }

Ответы (1 шт):

Автор решения: Zufir

У ConfigureAppConfiguration есть перегрузка, которая принимает Action от двух параметров: контекста и конфигурации. Через контекст можете получить требуемое свойство.

var host = Host
            .CreateDefaultBuilder()
            .ConfigureAppConfiguration((context, config) =>
            {
                config.SetBasePath(context.HostingEnvironment.ContentRootPath);
                config.AddEnvironmentVariables();
                config.AddJsonFile("appsettings.json");
            })
            .UseConsoleAppFramework(args)
            .ConfigureLogging(x =>
            {
                x.ClearProviders();
                x.AddSacmSerilog(true);
            })
            .Build();

await host.Services.InitializeEfCore();

await host.RunAsync();
→ Ссылка