我有一个 dotnet 核心项目,我将重要的示例数据从 XML 导入。
XDocument sampleData = XDocument.Load(@"seed/Import_sampleData.xml");
在终端中,当我使用命令dotnet run执行它时,它会按预期加载数据,但在 Visual Studio Code 中,当我尝试运行调试器时会得到不同的结果:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file '/Users/Chris/Google Drive/Repos/project/project.api/seed/Import_sampleData.xml'.
我不确定问题是什么,我认为调试器也使用dotnet run那么为什么它的行为会有所不同?
正如这里所建议的,这是我 project.json 中的 copyToOutput 设置。xml 文件现在被复制到构建时的 bin 文件夹中,但仍然返回文件未找到异常:
"copyToOutput": {
"include": [
"config.json",
"Certificate.pfx",
"seed\\"
]
}