Question: Dotnet core app not found appsettings.json in production

Question

Dotnet core app not found appsettings.json in production

Answers 0
Added at 2016-12-27 12:12
Tags
Question

I've developed a Web Api + Angular JS application that work well in Dev Env.

When I've deploy it under linux box, it fails to load appsettings.* when launched as service (using kestrel).

When I launch it manually, from the folder where it is installed, it runs well, but if i try from root path, using full path, it fails the same way as in service mode.

Should I create a sh script to launch it as service or could I modify something in my Program/Startup classes?

Program.cs :

    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }

Startup.cs

    public Startup(IHostingEnvironment env)
    {
        _env = env;
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = builder.Build();
    }
Answers
Source Show
◀ Wstecz