我试图在我的升级后的Asp.Net Core RC2应用程序的静态void main中获取配置值。在Startup的构造函数中,我可以注入IHostingEnvironment,但无法在静态方法中执行此操作。
我正在遵循https://github.com/aspnet/KestrelHttpServer/blob/dev/samples/SampleApp/Startup.cs,但希望将我的pfx密码放在appsettings中(是的,它应该在用户机密中,并最终到达那里)。
public Startup(IHostingEnvironment env){}
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile("hosting.json");
builder.AddEnvironmentVariables();
var configuration = builder.Build();
...
var host = new WebHostBuilder()
.UseKestrel(options =>
{
// options.ThreadCount = 4;
options.NoDelay = true;
options.UseHttps(testCertPath, configuration["pfxPassword"]);
options.UseConnectionLogging();
})
}