首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >YAML文件在构建时不会添加到bin\debug (.NET核心)

YAML文件在构建时不会添加到bin\debug (.NET核心)
EN

Stack Overflow用户
提问于 2020-03-11 21:30:07
回答 2查看 678关注 0票数 0

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

我在Startup.cs中这样做:

代码语言:javascript
运行
复制
   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文件而不需要我自己手动添加它?

EN

回答 2

Stack Overflow用户

发布于 2020-03-11 21:36:20

只需在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

票数 4
EN

Stack Overflow用户

发布于 2020-03-11 21:48:15

在Visual Studio中右键单击该文件,并将Build Action设置为Content,将Copy to Output Directory属性设置为Copy if newer

这将在您的项目(.csproj)文件中添加以下标记,该标记将告诉SDK在构建应用程序时将文件复制到输出文件夹:

代码语言:javascript
运行
复制
<ItemGroup>
    <Content Include="_config.yml">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemGroup>

当然,您也可以通过直接编辑(在Visual Studio中编辑项目->编辑项目文件)来手动将上述内容添加到.csproj文件中。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60637222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档