0

我有一个 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\\"        
  ]
}
4

1 回答 1

0

我想通了...基本上我有 2 个库项目,然后我的 api 项目都在一个子文件夹下。所以调试器从包含三个项目的根工作区文件夹开始。我将 cwd 更改为在我的 api 项目中启动,因为其他项目通过依赖项被拉入其中,然后它立即在我的项目中找到了 xml 文件。

于 2016-11-11T02:30:33.867 回答