Asp.net core 在生产环境中发布并运行ASP.NET Core 1.0应用程序
在ASPNETCORE 1.0应用程序上,我在启动时具有以下功能:Asp.net core 在生产环境中发布并运行ASP.NET Core 1.0应用程序,asp.net-core,asp.net-core-1.0,Asp.net Core,Asp.net Core 1.0,在ASPNETCORE 1.0应用程序上,我在启动时具有以下功能: public Startup(IHostingEnvironment hostingEnvironment) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder .SetBasePath(hostingEnvironment.ContentRootPath) .AddJsonFile("settings.json",
public Startup(IHostingEnvironment hostingEnvironment) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder
.SetBasePath(hostingEnvironment.ContentRootPath)
.AddJsonFile("settings.json", false, true)
.AddJsonFile($"settings.{hostingEnvironment.EnvironmentName}.json", false, true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
我的项目中有2个设置文件:
settings.json
settings.production.json
我使用命令行发布了该项目:
set ASPNETCORE_ENVIRONMENT=production
dotnet publish --configuration Release
发布的文件包括settings.json
,但不包括settings.production.json
。而settings.json
确实包含仅在settings.production.json
中的属性。它们不应该在发布时合并吗
除此之外,当我将文件复制到服务器时,如何确保应用程序在生产模式下运行
我需要在
Web.config
上执行任何操作吗?您需要更新project.json
以将设置.production.json
文件添加到publishOptions
的include
部分:
{
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"settings.json",
"settings.production.json",
"web.config"
]
}
}
好的,当服务器上有应用程序时,如何“告诉它”在生产环境中运行?您应该在将在生产环境中运行应用程序的服务器上设置环境变量
ASPNETCORE\u environment=production
。有关更多详细信息,请参阅本文讨论的是环境变量,而不是在服务器中设置它们以及各种选项。然后,我发现: