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
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.
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.
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.”
Deleting the "External Script Editor Args" args at least allows VIsual Studio Code to open, but without the relevant file. Aaarrggghhhh I give up!!!
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.
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.
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!
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"
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With