2
.netコア2コンソールアプリケーションにappsettings変換を追加しようとしています。.Net core 2 console appsettings
- appSettings.json
- appSettings.Test.json
- appSettings.Prod.json
私は、次のコードは、asp.netコアの作品を発見した:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange:
true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional:
true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
しかし、コンソールアプリケーションにIHostingEnvironment
がないので、env.EnvironmentName
を取得する方法はわかりません。
すべてのヘルプは、[
可能な複製のためのプリプロセッサディレクティブを使用して何かを見つけることができませんでし理解されるであろう開始を使用するASP.NET5コンソールアプリケーションの[アップクラス](https://stackoverflow.com/questions/30257710/using-startup-class-in-asp-net5-console-app-ication#30259936) – CalC
これは、IApplicationEnvironmentが現在存在するため、重複していません https://github.com/aspnet/PlatformAbstractions/issues/37 –
「Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application」には環境情報が含まれていません –