首页 > 解决方案 > YAML 文件未添加到构建时的 bin\debug (.NET Core)

问题描述

我的项目根目录中有一个 _config.yml YAML 文件。

我在 Startup.cs 中做:

   var builder = new ConfigurationBuilder()     
        .SetBasePath(AppContext.BaseDirectory)   
        .AddYamlFile("_config.yml");              
    Configuration = builder.Build(); 

当我构建并运行项目时,出现以下错误:

System.IO.FileNotFoundException: The configuration file '_config.yml' was not found and is not optional. The physical path is 'C:\Users\user\OneDrive\Documenten\Descent.Bot\bin\Debug\n etcoreapp3.1\_config.yml'.

不应该通过构建项目自动添加 YAML 文件bin\Debug吗?有bin\Debug没有我自己手动添加 YAML 文件的方法?

标签: c#.netasp.net-core.net-core

解决方案


您可以在 Visual Studio 中右键单击该文件,然后单击属性。在那里您将看到将文件复制到输出目录的选项。

在后台,Visual Studio 正在 .csproj 中创建一个 None 来处理流程

您可以在这里阅读更多内容 https://social.technet.microsoft.com/wiki/contents/articles/53248.visual-studio-copying-files-to-debug-or-release-folder.aspx


推荐阅读