ASP.NET Core 中默认的WebRoot是在哪里指定为的wwwroot,翻源码没找到,请告知谢谢。
public static class HostingEnvironmentExtensions { public static void Initialize(this IHostingEnvironment hostingEnvironment, string contentRootPath, WebHostOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrEmpty(contentRootPath)) { throw new ArgumentException("A valid non-empty content root must be provided.", nameof(contentRootPath)); } if (!Directory.Exists(contentRootPath)) { throw new ArgumentException($"The content root '{contentRootPath}' does not exist.", nameof(contentRootPath)); } hostingEnvironment.ApplicationName = options.ApplicationName; hostingEnvironment.ContentRootPath = contentRootPath; hostingEnvironment.ContentRootFileProvider = new PhysicalFileProvider(hostingEnvironment.ContentRootPath); var webRoot = options.WebRoot; if (webRoot == null) { // Default to /wwwroot if it exists. var wwwroot = Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot"); if (Directory.Exists(wwwroot)) { hostingEnvironment.WebRootPath = wwwroot; } } ..... }
Hosting有个UseWebRoot的扩展方法可以改变wwwroot这个目录。可以从这个出发。
在Build一个IWebHost的时候就可以指定这个的目录。
https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs#L259