相当于 .NET Core 的 App.config 转换? [英] Equivalent to App.config transforms for .NET Core?

查看:21
本文介绍了相当于 .NET Core 的 App.config 转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 .NET Core 控制台应用程序(不是 ASP.NET Core Web 应用程序).在 .NET Framework 中,我会有一个 App.configApp.Debug.config 和一个 App.Release.config 文件,后者 2 用于改造前者.这让我可以根据我是在创建调试版本还是发布版本来更改各种设置.

I'm writing a .NET Core console application (NOT an ASP.NET Core web application). In .NET Framework I would have an App.config, and App.Debug.config, and an App.Release.config file, the latter 2 for transforming the former. This allowed me to change various settings based on whether I was creating a debug or a release build.

现在有了 .NET Core,您应该改用 appsettings.json.很好,但是我如何使用它进行调试和发布转换?我已经阅读了一些关于使用环境变量来确定您是在发布环境还是调试环境中的内容,但我真的不想这样做,而且它无论如何都不适合控制台应用程序.那么如何以与在 .NET Framework 中的方式类似的方式转换配置文件?

Now with .NET Core, you're meant to use appsettings.json instead. Fine, but how do I do my debug and release transforms with this? I've read something about using an environment variable to determine whether you're in a release or debug environment but I really don't want to do this and it's not really appropriate for console applications anyway. So how can I transform config files in a similar way to how it was done in .NET Framework?

推荐答案

我找到的简短答案是:使用 SlowCheetah.它为 .NET Core 实现 XDT 转换,此外还允许使用 JDT 进行 JSON 转换.

The short answer that I found to this is: use SlowCheetah. It implements XDT transformations for .NET Core and in addition allows JSON transformations too with JDT.

这篇关于相当于 .NET Core 的 App.config 转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆