3
votes

In my ASP.NET 5 (core, vNext) application I have:

  • appsettings.test.json
  • appsettings.development.json
  • appsettings.staging.json
  • appsettings.production.json
  • appsetings.cloud.json

Each of these include different connection strings (for different environments).

Problem

When I publish my application to Azure, it automatically uses the Production environment.

I want to use the Cloud environment, when I publish to Azure.

Note

I am using the one month free trial of Azure, which wont allow me to create deployment slots (I need to upgrade).

Question

So, is there anyways I can publish to Azure in my custom environment (Cloud) by default?

2

2 Answers

2
votes

So, is there anyways I can publish to Azure in my custom environment (Cloud) by default?

Yes.

The easiest way is the Azure portal. Go to MyWebApp > Settings > Application Settings > App settings. Set the ASPNET_ENV variable to Cloud.

ASPNET_ENV App settings

We can test this with a simple ASP.NET Core application.

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json");

        builder.Build();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.Run(async (context) =>
        {
            await context.Response
                .WriteAsync("Hello from " + env.EnvironmentName);
        });
    }
}

It works as expected.

Hello from Cloud

0
votes

Try setting ASPNET_ENV in your command line. Like set ASPNET_ENV = cloud, you can also change the environemnt in VS by right clicking on your project and selecting properties, then click debug. In the Environment vars you can edit the Hosting Environment. You can also look at this issue for more ways to change the environment.