启动配置中的 .SetBasePath 和 .UseContentRoot 有什么区别?
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
How can I use IConfiguration from my integration tests?
最佳答案
SetBasePath
是 IConfigurationBuilder
的扩展方法, 设置定位配置文件时使用的路径:
Sets the FileProvider for file-based providers to a PhysicalFileProvider with the base path.
例如,在定位
appsettings.json
时您在问题中指定的文件,它将在使用 Directory.GetCurrentDirectory()
检索的路径中查找UseContentRoot
是 IWebHostBuilder
的扩展方法, 设置 contentRoot
Web 主机的 key :This setting determines where ASP.NET Core begins searching for content files, such as MVC views.
contentRoot
使用的默认值关键是:[...] the folder where the app assembly resides.
这意味着,对于典型设置,两者的路径最终将相同,但这不是必需的。
关于c# - Net Core : Difference between . Startup.Cs 中的 SetBasePath 和 .UseContentRoot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321773/