简体   繁体   English

在Core 2.0 Web API项目中引用了.net Framework 4.x程序集的app.config迁移?

[英]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.

相关问题 .NET 5 项目不能真正与旧的第 3 方一起使用 .NET 框架 2.x/4.x 程序集 - .NET 5 Project not really working with old 3rd Party .NET Framework 2.x/4.x assemblies app.config 未加载到 .Net Core MSTests 项目中 - app.config not beeing loaded in .Net Core MSTests project .NET / C#库项目实体框架app.config - .NET/C# library project entity framework app.config 程序集,Web.config和App.Config-构建故障转移逻辑 - Assemblies, Web.config and App.Config — Building failover logic 将 class 库项目升级到 .net 标准 2.1,其中 .net 框架 4.X 项目已引用该标准 - Upgrading class library project to .net standard 2.1 where this has been referenced by .net framework 4.X projects .NET Core API 调用 .NET 项目中的方法表示在 app.config 文件中找不到连接字符串 - .NET Core API call to a method in a .NET Project is saying it can't find Connection strings in the app.config file 如何从 DBContext(实体框架核心)中的 App.config(不是 .net 核心应用程序)中读取值 - How to read value from App.config (not .net core app) in DBContext (which is entity framework core) 在 .Net Core 中使用 app.config - Using app.config in .Net Core 相当于App.config转换.NET Core? - Equivalent to App.config transforms for .NET Core? 从 .net 核心集成测试项目加载引用的程序集不包括来自测试的 API 的引用项目 - Load referenced assemblies from a .net core Integration Test project doesn't include referenced projects from tested API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM