1

On an ASPNETCORE 1.0 application I have the following on Startup:

public Startup(IHostingEnvironment hostingEnvironment) {

  ConfigurationBuilder builder = new ConfigurationBuilder();

  builder
    .SetBasePath(hostingEnvironment.ContentRootPath)
    .AddJsonFile("settings.json", false, true)
    .AddJsonFile($"settings.{hostingEnvironment.EnvironmentName}.json", false, true);
  builder.AddEnvironmentVariables();

  Configuration = builder.Build();

}

I have 2 settings files on my project:

settings.json
settings.production.json

I published the project using the command line:

set ASPNETCORE_ENVIRONMENT=production
dotnet publish --configuration Release

The published files include settings.json but not settings.production.json. And settings.json does include the properties which are only in settings.production.json. Shouldn't they be merged on publish?

In top of this how to make sure that the application runs on production mode when I copy the files to my server?

Do I need to do anything on Web.config?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

1 Answers1

1

You need to update your project.json to add your settings.production.json file to the include section of publishOptions:

{
  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "settings.json",
      "settings.production.json",
      "web.config"
    ]
  }
}
Sock
  • 5,323
  • 1
  • 21
  • 32
  • Ok, and when I have the application on the server how to "tell it" to run in production? – Miguel Moura Jul 25 '16 at 21:01
  • 1
    You should set the environment variable `ASPNETCORE_ENVIRONMENT=production` on the server on which will be running your app in production. See https://docs.asp.net/en/latest/fundamentals/environments.html for more details – Sock Jul 26 '16 at 06:45
  • That post talks about Environment Variables but not so much about setting them in the server and the various options. I then found the following: http://stackoverflow.com/questions/31049152/asp-net-5-publish-to-iis-setting-aspnet-env-variables – Miguel Moura Jul 26 '16 at 09:16