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.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....