asp.net-core – dotnet publish不会发布正确的appsettings {env.EnvironmentName} .json

前端之家收集整理的这篇文章主要介绍了asp.net-core – dotnet publish不会发布正确的appsettings {env.EnvironmentName} .json前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我在命令行中发出以下命令:

dotnet publish -o“./../output”-c Release

dotnetcli正确地发布项目。但是它不会复制appsettings.Production.json文件,只有appsettings.json。

为什么是这样?我已经google了,阅读官方核心文档,但没有找到如何正确的环境appsettings.json应该在发布输出结束。

我应该将appsettings.Production.json手动复制到已发布的文件夹吗?

解决方法

“在你的project.json文件中,你有部分publishOptions与分部分,你已经有一些文件,如”appsettings.json“:
"publishOptions": {
  "include": [
    "appsettings.json","hosting.json","project.json","web.config"
  ]
},

您应该将“appsettings.Production.json”添加到此数组中。

基于评论的更新:

>请记住,所有appsettings。*。json文件,如appsettings.development.json,appsettings.staging.json和appsettings.production.json将总是在所有环境中结束。你不能简单地使用project.json处理它,因为它不支持任何条件规则。这将在未来更改,当project.json将replaced back到msbuild和.csproj。如果这对您的应用程序至关重要,请考虑使用其他配置存储,如环境变量,数据库等。
>注意,该顺序很重要,因为如果它们存在于多个位置,则确定应用哪些设置。从documentation

The order in which configuration sources are specified is important,as this establishes the precedence with which settings will be applied if they exist in multiple locations. In the example below,if the same setting exists in both appsettings.json and in an environment variable,the setting from the environment variable will be the one that is used. The last configuration source specified “wins” if a setting exists in more than one location. The ASP.NET team recommends specifying environment variables last,so that the local environment can override anything set in deployed configuration files.

原文链接:https://www.f2er.com/aspnet/254161.html

猜你在找的asp.Net相关文章