这既是一个问题,也是一个答案。我已经解决了我的问题,但是似乎有点不对。
我最初的问题是在bitbucket管道中运行我的asp.net核心集成测试会导致System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.
,有些解决方案要求通过sysctl
更改某些设置,但这就是restricted by bitbucket,所以这对我来说不是一个选择。
如these stackoverflow answers中所述,解决此问题的第二种方法是关闭reloadOnChange
。
我的新问题是,我们如何[[最佳为此进行测试WebApplicationFactory
?
JsonConfigurationSource
并将ReloadOnChange
设置为false
。完整解决方案:
public class TestApplicationFactory : WebApplicationFactory<Startup>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration(config =>
{
foreach (var source in config.Sources)
{
if (source is JsonConfigurationSource)
{
var jsonConfigSource = (JsonConfigurationSource) source;
jsonConfigSource.ReloadOnChange = false;
}
}
});
}
}
我没有尝试过的另一种解决方案可能是overrideCreateWebHostBuilder()
。但是,似乎CreateWebHostBuilder()
中有更多代码和大量复制和粘贴。我想念什么吗?有更好的方法吗?
您可以使用builder.ConfigureAppConfiguration
(请参阅builder.ConfigureHostConfiguration
)为
主机显式配置要读取的文件。
docs主机配置已加载。从3.0开始的ASP.NET Core是基于通用主机(而不是以前版本的Web主机)构建的。