VSCode 'Unable to open file.cs: File Not Found'

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

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

Unable to open 'XXXController.cs':File Not Found (file://Controllers/XXXController.cs)

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?

Edit: 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?

Regards Dave

回答1:

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.

i.e.

{     "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"         }     ] } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!