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.

28 lines
1.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
namespace Ds.WMS.WebCore.appstartup
{
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;
}
}
}