我在项目的根目录下有一个_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文件而不需要我自己手动添加它?
发布于 2020-03-11 21:36:20
只需在Visual studio中右键单击该文件,然后单击属性即可。在那里您将看到将文件复制到输出目录的选项。
在幕后,Visual studio在.csproj中创建了一个None来处理流
发布于 2020-03-11 21:48:15
在Visual Studio中右键单击该文件,并将Build Action设置为Content,将Copy to Output Directory属性设置为Copy if newer。
这将在您的项目(.csproj)文件中添加以下标记,该标记将告诉SDK在构建应用程序时将文件复制到输出文件夹:
<ItemGroup>
<Content Include="_config.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>当然,您也可以通过直接编辑(在Visual Studio中编辑项目->编辑项目文件)来手动将上述内容添加到.csproj文件中。
https://stackoverflow.com/questions/60637222
复制相似问题