【发布时间】:2016-11-10 17:38:55
【问题描述】:
我有一个 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\\"
]
}
【问题讨论】:
-
我认为当你从 Visual Studio 运行它时,它使用二进制文件夹作为基本文件夹,当你从控制台运行它时,它使用项目文件夹。您是否尝试将文件复制到构建目录(使用 project.json
copyToOutput? -
我将目录添加到 copyToOutput,当项目构建时,我现在可以在 bin 的子文件夹中看到 xml 文件,但我仍然得到相同的行为。找不到文件
标签: asp.net-core visual-studio-code omnisharp