加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 18:55:35 所属栏目:asp.Net 来源:网络整理
导读:当我在命令行中发出以下命令: dotnet publish -o“./../output”-c Release dotnetcli正确地发布项目。但是它不会复制appsettings.Production.json文件,只有appsettings.json。 为什么是这样?我已经google了,阅读官方核心文档,但没有找到如何正确的环境
当我在命令行中发出以下命令:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读