json保存在bin目录中

json保存在bin目录中

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

问题描述

我是 net core 2.0 的新手。

我正在连接到datbase。我曾经使用 App.Config Web.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.

当我编译应用程序时,<$ c $ bin 目录中未生成c> 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文件。

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.

此文档还指出,以确保将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目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:55