I am having problems with running my dotnet core 2.0 API (on Ubuntu 16.04 using .NET Core CLI) using the correct Environment settings.
I added into the "~/.bash_profile" the following:
ASPNETCORE_ENVIRONMENT=staging
When i run the project (using dotnet run) it seems to work correctly, It detects that it should be on staging. However, when i compile using "dotnet publish" and try to run it using:
nohup dotnet API.dll --urls "http://*:1337" &> /var/log/dotnetlogs
it does not seem to detect the environment variable and always defaults to using the "Production" environment.
Startup.cs:
public Startup(IHostingEnvironment 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();
}
Program.cs
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseConfiguration(config)
.UseStartup<Startup>()
.Build();
host.Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
Any idea how i can get this working?
launchSettings.json
– Isaac Kleinman