[英]app.config migration for .net framework 4.x assemblies referenced in Core 2.0 Web API project?
I have a .net core web api project that references 4.x assemblies that have app.config settings. 我有一个.net核心Web api项目,该项目引用具有app.config设置的4.x程序集。 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?
我可以在不修改旧程序集的情况下将app.config设置转换为appsettings.json还是仅将旧程序集的设置放入app.config文件中? If I just drop in app.config files, how can I change those settings on publish?
如果仅放入app.config文件,如何在发布时更改这些设置?
In Core 2.0 Web API
you can point your configuration to old app.config
as well this way: 在
Core 2.0 Web API
您也可以通过以下方式将配置指向旧的app.config
:
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). 然后,您将能够通过按键(看起来像冒号分隔的XML路径)来访问您的连接字符串(和其他应用程序设置)。 For instance for the connection string section you can get the value for connection name
MyConnectionName
this way: 例如,对于连接字符串部分,您可以通过以下方式获取连接名称
MyConnectionName
的值:
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: 或者,您可以按照此处的详细说明实现自己的
LegacyConfigurationProvider
,并具有如下所示的内容:
IConfigurationRoot configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.Add(new LegacyConfigurationProvider())
.Build();
See also Configuration in ASP.NET Core . 另请参见ASP.NET Core中的配置 。
So what I ended up doing is just adding app.config files. 因此,我最终要做的只是添加app.config文件。 I also added an app.release.config and rename it to app.config as part of my publish process.
在发布过程中,我还添加了一个app.release.config并将其重命名为app.config。 I could not use config transformations.
我无法使用配置转换。 I could not get that to work in Azure CI at all.
我根本无法在Azure CI中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.