I have a .net core web api project that references 4.x assemblies that have app.config settings. Can I convert the app.config settings to appsettings.json without modifying the old assemblies or do I just drop in an app.config file with the settings for the older assemblies? If I just drop in app.config files, how can I change those settings on publish?
In Core 2.0 Web API
you can point your configuration to old app.config
as well this way:
IConfigurationRoot configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.AddXmlFile("app.config")
.Build();
Then you will be able to access for instance your connection string (and other app settings) by the keys (looks like a colon separated XML path). For instance for the connection string section you can get the value for connection name MyConnectionName
this way:
key: "connectionStrings:add:MyConnectionName:connectionString"
value: "...your connection string..."
Or you can implement your own LegacyConfigurationProvider
as described here in details and have something like this:
IConfigurationRoot configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.Add(new LegacyConfigurationProvider())
.Build();
See also Configuration in ASP.NET Core .
So what I ended up doing is just adding app.config files. I also added an app.release.config and rename it to app.config as part of my publish process. I could not use config transformations. I could not get that to work in Azure CI at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.