猿问

如何让ASP.NET Core集成测试中的TestServer以Development环境运行

默认是以Production环境运行的,想让它以Development环境运行,以便可以读取appsettings.Development.json配置文件。

每次 export ASPNETCORE_ENVIRONMENT=Development  太麻烦了,有没有更简单的方法?

var builder = WebHost.CreateDefaultBuilder()
    .UseStartup<Startup>();                

var server = new TestServer(builder);
_httpClient = server.CreateClient();


慕盖茨4494581
浏览 642回答 1
1回答

牛魔王的故事

在 stackoverflow 上找到了解决方法,在集成测试中添加如下的代码:Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT",&nbsp;"Development");
随时随地看视频慕课网APP
我要回答