Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 590
David Waterworth Avatar asked Apr 14 '18 00:04

David Waterworth


People also ask

Can't open file error VS Code?

For resolving this issue, I closed the VSCode and again imported folder again as Path of folder got changed in mine conditions. If this doesn't work, you can uninstall VSCode and then reinstall it. Show activity on this post.

Can you run a CS file in Visual Studio code?

In Visual Studio Code Open the folder containing your Program. cs file, as long as their is a project file in that folder you can open a new terminal window and type dotnet build then after it builds dotnet run.

Why multiple files are not opening in VS Code?

If VS Code doesn't allow you to open multiple files, the issue most likely lies in the program settings. To fix that, do the following: Launch VS Code, then click “File” at the upper part of the program window. Select “Preferences.”

How to open Visual Studio Code without the relevant file?

Deleting the "External Script Editor Args" args at least allows VIsual Studio Code to open, but without the relevant file. Aaarrggghhhh I give up!!!

How to open a script file in Visual Studio Code?

Scripts will open from Unity using Visual Studio Code, but it won't open the C# project or use intellisense. To fix that, I then go to 'File > Open Folder...' in Visual Studio Code and open the Unity project folder. If Visual Studio Code is closed, then I have to repeat the process.

How do I open a Visual Studio code file in Unity?

For what it's worth, my solution to this problem was to configure Windows to open .cs files in Visual Studio Code by default, and then change the 'External Script Editor' setting to 'Open by File Extension' in Unity preferences. Scripts will open from Unity using Visual Studio Code, but it won't open the C# project or use intellisense.

Why doesn't MSBuild report full paths for errors?

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 asks.json seems to resolve the issue. Thanks for contributing an answer to Stack Overflow!


1 Answers

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"
        }
    ]
}
like image 74
David Waterworth Avatar answered Oct 27 '22 00:10

David Waterworth