C# ContentRootPath在开发和Azure web应用程序中不同
当我将我的Dot Net核心web应用程序部署到Azure时,C# ContentRootPath在开发和Azure web应用程序中不同,c#,azure,.net-core,C#,Azure,.net Core,当我将我的Dot Net核心web应用程序部署到Azure时,环境.ContentRootPath变量设置为[myproject]/wwwroot。然而,在开发中,它只是[myproject] 为什么在Azure部署中会发生变化 我怎样才能使它保持一致 作为参考,这是我的IWebHost public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args)
环境.ContentRootPath
变量设置为[myproject]/wwwroot
。然而,在开发中,它只是[myproject]
为什么在Azure部署中会发生变化
我怎样才能使它保持一致
作为参考,这是我的IWebHost
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((builderContext, config) =>
{
var env = builderContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
if (env.IsDevelopment())
config.AddUserSecrets<Startup>();
config.AddEnvironmentVariables();
})
.UseSetting("detailedErrors", "true")
.UseApplicationInsights()
.UseStartup<Startup>()
.CaptureStartupErrors(true)
.Build();
公共静态IWebHost BuildWebHost(字符串[]args)=>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((builderContext,config)=>
{
var env=builderContext.HostingEnvironment;
config.AddJsonFile(“appsettings.json”,false,true)
.AddJsonFile($“appsettings.{env.EnvironmentName}.json”,true,true);
if(env.IsDevelopment())
config.AddUserSecrets();
config.AddEnvironmentVariables();
})
.UseSetting(“详细错误”、“真”)
.UseApplicationInsights()
.UseStartup()
.CaptureStartupErrors(真)
.Build();
使用时,您会发现您的web内容部署到D:\home\site\wwwroot
,如下所示:
默认情况下,D:\home\site\wwwroot
将用作内容根目录,主机将在Azure Web App上托管应用程序时搜索内容文件(例如MVC视图文件等)
在开发过程中,应用程序从项目的根文件夹启动,因此项目的根文件夹用作内容根文件夹
根据我的理解,您可能会误解项目中的wwwroot
文件夹与Azure Web App上用于存储Web内容的wwwroot
文件夹
此外,您可以使用UseContentRoot
自定义内容根文件夹。如果路径不存在,主机将无法启动。你可以关注细节