我的项目根目录中有一个_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:UsersuserOneDriveDocumentenDescent.BotbinDebugn
etcoreapp3.1_config.yml'.
难道不应该通过构建项目将YAML文件自动添加到binDebug
中吗?有没有一种方法可以在binDebug
中添加YAML文件,而无需我自己手动添加?
在Visual Studio中右键单击该文件,并将Build Action
设置为Content
,将Copy to Output Directory
属性设置为Copy if newer
。
这将向您的项目(.csproj
(文件添加以下标记,这将告诉SDK在构建应用程序时将文件复制到输出文件夹:
<ItemGroup>
<Content Include="_config.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
当然,您也可以通过直接编辑.csproj
文件来手动将上述内容添加到该文件中(在Visual Studio中,项目->编辑项目文件(。
您可以在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