3

I've got an ASP.Net Core project, targeting .Net framework, so we use a mixture of the app.config and the appsettings.json. We're migrating to Azure App Services, so we want to use the built in publish functionality. The appsettings.json was easy to configure as I created an appsettings.Production.json and added reference to this in our code and then set the value in the Azure application settings.

builder.AddJsonFile($"appsettings.{Environment.EnvironmentName}.json", optional: true);   

I can't seem to figure out a way to get the config files working though. The app.config publishes it's output into the exe.config that's produced. I've tried replicating various online examples, to use an app.release.config to transform this, but none work. We use Entity Framework 6 from .Net Framework, so it's expecting to read from the config file, as well as some web service connections.

Is there any way I can do this out of the box?

Thanks, David

McGuireV10
  • 9,572
  • 5
  • 48
  • 64
David Hendrick
  • 93
  • 2
  • 13
  • Did you call `SetBasePath` first? Typically it is set to `Directory.GetCurrentDirectory` on .NET Framework. Are you sure the environment variable is defined up on Azure? Maybe post the whole block that sets up config? – McGuireV10 Mar 08 '18 at 16:51
  • Hi @McGuireV10, Thanks for coming back to me. Is this for the app.config also? I have the appsettings.json working perfectly, and the environmental variable in Azure is switching it to the appsettings.production.json perfectly. I have some connection strings etc. in the app.config, which go into the exe.config upon publishing. I need to transform those as they are required by our .Net Framework libraries. Thanks, David – David Hendrick Mar 09 '18 at 10:07
  • Also, I have called SetBasePath, but am assuming this is all related to the appsettings.json builder.SetBasePath(Directory.GetCurrentDirectory()); – David Hendrick Mar 09 '18 at 10:12
  • Since app.config is XML, have you added the XML configuration [extension](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.xmlconfigurationextensions?view=aspnetcore-2.0) and tried that? – McGuireV10 Mar 09 '18 at 10:44
  • Is this to the builder in the startup class? Would you have an example please? Like this: IConfigurationRoot configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .AddXmlFile("app.config") .Build(); – David Hendrick Mar 09 '18 at 10:56
  • Yes, another builder line. The syntax should be similar, I haven't used the XML one specifically. It's all extensions these days (I'm using command-line, environment, and Azure extensions, on top of JSON). – McGuireV10 Mar 09 '18 at 11:12
  • The outputted exe.config doesn't get the app.release.config data though. This is done as part of the publishing, so I'm not sure that will help? I can delete the app.config from Azure and it still runs, using the exe.config version, generated during the publish. – David Hendrick Mar 09 '18 at 12:49
  • 1
    Possible duplicate of [Using app.config in .Net Core](https://stackoverflow.com/questions/45034007/using-app-config-in-net-core) – Liam Aug 08 '18 at 09:12

0 Answers0