Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode constantly asks me to Restore

VSCode 1.20.0 on Windows 10, with C# extension ms-vscode.csharp 1.14.0. VSCode Terminal points to bash (Windows Subsystem for Linux) VSCode is opened on a folder containing a .NET CORE 2.0 C# project

Everything is fine, intellisense works, project references are understood.

Whenever I switch focus to the VS Code terminal and type "dotnet build" or "dotnet test", VSCode gets confused. Red Squigglies underline every line of source code, intellisense stops working, and VSCode opens two info boxes that say

Info: There are unresolved dependencies from src\Project.csproj. Please execute the restore command to continue. Info: There are unresolved dependencies from test\Project.Tests.csproj. Please execute the restore command to continue.

When I click the "Restore" button inside the info box, about 15 seconds later the project works again. But why, this happens all the time, I tend to dotnet build frequently. Can I configure VS Code differently to avoid this problem? It doesn't seem right that building code would break the editor functionality so I must be doing something wrong.

EDIT:

This problem seems to repro only if I dotnet build or dotnet test in WSL\bash (whether Internal or External Terminal). It doesn't seem to repro when I build or test in an external cmd.exe

EDIT:

cmd.exe dotnet --info

.NET Command Line Tools (2.1.4)

Product Information: Version: 2.1.4 Commit SHA-1 hash: 5e8add2190

Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.4\

Microsoft .NET Core Shared Framework Host

Version : 2.0.5 Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54

WSL\bash $ dotnet --info

.NET Command Line Tools (2.0.3)

Product Information: Version: 2.0.3 Commit SHA-1 hash: eb1d5ee318

Runtime Environment: OS Name: ubuntu OS Version: 16.04 OS Platform: Linux RID: ubuntu.16.04-x64 Base Path: /usr/share/dotnet/sdk/2.0.3/

Microsoft .NET Core Shared Framework Host

Version : 2.0.3 Build : a9190d4a75f4a982ae4b4fa8d1a24526566c69df

like image 410
mipnw Avatar asked Feb 14 '18 20:02

mipnw


1 Answers

The reason this might be happening could be because VS Code is using Omnisharp running on Windows - when you build using Bash, you are building for linux, and therefore all the reference paths generated in files in the obj folder will be linux paths, not Windows paths.

When Omnisharp looks for the referenced dependencies for intellisense in VS Code, it can't find them, and so VS Code requests you to restore your project.

You could confirm by checking any of the files in the obj folder, and looking at the paths.

EDIT - 2019

Just an update on this - things are looking promising. We will soon be able to use the VS Code Remote Extension Pack to run extensions INSIDE the WSL environment (or Docker Containers or even over SSH sessions). This is pretty awesome - it should mean that not only does our code run in WSL, but the extensions will also - and therefore OmniSharp extension will be running in WSL, using the Linux binaries for intellisense etc.

I am personally pretty excited by the new tools Microsoft is releasing. Its a really god time to be developing on the Windows platform with tools like WSL, VS Code, Docker and Hyper V... and the upcoming WSL 2 is going to be incredible (FULL Linux Kernal baked into Windows!!!)

like image 111
Clay Avatar answered Nov 18 '22 04:11

Clay