You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
|
|
|
|
namespace Ds.WMS.WebCore
|
|
|
|
|
{
|
|
|
|
|
public static class WebApplicationFactoryExtensions
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static WebApplicationBuilder UseMyConfiguration(this WebApplicationBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
// 获取应用程序的工作目录
|
|
|
|
|
var workingDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
|
|
|
|
|
|
|
|
|
// 首先加载appsettings.json
|
|
|
|
|
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
|
|
|
|
|
|
|
// 搜索工作目录及其所有子目录中的所有.json文件
|
|
|
|
|
foreach (var file in workingDirectory.EnumerateFiles("*.json", SearchOption.AllDirectories))
|
|
|
|
|
{
|
|
|
|
|
// 如果文件名不是appsettings.json,则加载配置文件
|
|
|
|
|
if (file.Name != "appsettings.json")
|
|
|
|
|
{
|
|
|
|
|
builder.Configuration.AddJsonFile(file.FullName, optional: true, reloadOnChange: true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|