VSCode '无法打开 file.cs:找不到文件' [英] VSCode 'Unable to open file.cs: File Not Found'
问题描述
我通过重命名文件夹或其他东西破坏了我的 vscode 项目.不完全确定发生了什么.问题是虽然我仍然可以构建和运行没有问题,但有些东西已经搞砸了,所以当我收到编译错误时,例如当我双击它说
I've broken my vscode project by renaming the folder or something. Not totally sure what happened. The problem is whilst I can still build and run no problems, something has been messed up so that when I get a compilation error for example when I double click on the message it says
无法打开XXXController.cs":找不到文件(file://Controllers/XXXController.cs)
Unable to open 'XXXController.cs':File Not Found (file://Controllers/XXXController.cs)
似乎在我的源文件夹中的 3 个项目中的 1 个项目中丢失了 cs 文件的完整路径.我的印象是 vscode 没有维护项目中的文件列表,所以除了重新创建项目之外,我不知道如何恢复?
Somewhere along the line it seems to have lost the full path to the cs files for 1 of 3 projects in my source folder. I was under the impression that vscode doesn't maintain a list of files in the project so I'm at a loss to work out how I can recover other than recreating the project?
还有其他问题 - 智能感知似乎也不适用于该项目.
There are other issues as well - intellisense doesn't seem to work for this project either.
有人知道我如何尝试解决这个问题吗?
Does anyone have any ideas how I try and fix this?
它提供了创建丢失"文件的选项.当我这样做时,它会在 C:\Controllers\ 中创建一个新文件,而不是在 *.csproj 位置下的 \Controllers 文件夹中?
It presents an option to create the 'missing' file. When I do so it creates a new file in C:\Controllers\ rather than in the \Controllers folder under the *.csproj location?
问候戴夫
推荐答案
问题好像是msbuild在报错时默认不输出全路径,omnisharp-vscode需要全路径来解析文件,所以添加GenerateFullPaths=true .vscode\tasks.json 似乎解决了这个问题.
The problem appears to be that msbuild by default doesn't output full paths when it reports errors, omnisharp-vscode requires full paths to resolve files so adding GenerateFullPaths=true to the .vscode\tasks.json seems to resolve the issue.
即
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Test.Api/Test.Api.csproj",
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"problemMatcher": "$msCompile"
}
]
}
这篇关于VSCode '无法打开 file.cs:找不到文件'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!