net core 2.0 appsettings.json 保存在 bin 目录中 [英] net core 2.0 appsettings.json save on bin directory

查看:33
本文介绍了net core 2.0 appsettings.json 保存在 bin 目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 net core 2.0 的新手.

我正在连接到数据库.我习惯使用 App.ConfigWeb.Config 来设置连接字符串.但是在 net core 2.0 中使用 appsettings.json 文件代替.

I am connecting to datbase. I am used to use an App.Config or Web.Config to set the connection string. But in net core 2.0 uses appsettings.json file instead.

编译de应用程序时,bin目录下没有生成appsettings.json文件.因此,当我从控制台运行应用程序时 c>dotnet prj.dll 抛出异常,因为找不到连接文件.

When I compile de Application, appsettings.json file is not generated in bin directory. So when I run the appplication from Console c>dotnet prj.dll thrown an excepción because connection file is not found.

我的问题是...我必须手动将 appsettings.json 文件复制到 bin 目录,或者有没有办法将它保存在 bin 项目编译时的目录?

My question is... I have to copy appsettings.json file manually to bin directory or is there a way to save it in bin directory when Project is compiled?

谢谢

推荐答案

我一直在寻找这个问题的答案,我发现的大部分帖子都引用了 project.json 文件,该文件现已被弃用.csproj 文件 根据 3 月发布的本指南2017.

I've been looking for an answer to this question and most of the posts I've found reference the project.json file which has now been deprecated in favour of the .csproj file according to this guide published March 2017.

本文档还说明了您如何可以使用 .csproj 文件中的CopyToOutputDirectory"属性来确保将 appsettings.json 文件复制到构建时的输出目录:

This document also indicates how you can use the "CopyToOutputDirectory" attribute in your .csproj file to ensure your appsettings.json file is copied to the output directory on build:

<Project ...>
    ...
    <ItemGroup>
        <None Include="appsettings.json" CopyToOutputDirectory="Always" />
    </ItemGroup>
</Project>

.

这篇关于net core 2.0 appsettings.json 保存在 bin 目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆