dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 670 forks source link

OmniSharp Server keeps open handle to folder containing .sln #4323

Open chausner-audeering opened 3 years ago

chausner-audeering commented 3 years ago

Issue Description

The OmniSharp.exe process running in the background of VS Code keeps an open handle to the folder containing VS solution files even when the solution is deleted. The open handle prevents one from deleting the folder than previously contained the solution.

Note that the solution file does not even contain any C# but only C++ projects. I do have other .NET projects in subfolders of my VS code workspace folder though.

Steps to Reproduce

I am using CMake to build a C++ project using the Visual Studio generator. I am calling CMake in the VS Code terminal roughly like so:

rm -Recurse build # remove previous build folder if existing
mkdir build
cd build
cmake .. -G "Visual Studio 16 2019"
cmake --build .

As part of the configuration step, CMake generates a .sln file in the build folder which apparently OmniSharp opens in the background. As soon as I run my build script again, the script fails to delete the old build folder because OmniSharp Server still keeps an open handle to the folder (even though all files in it, including the .sln file are deleted). Also manually deleting the folder in Windows Explorer does not work, only killing the OmniSharp.exe process makes the folder deletable.

Logs

OmniSharp log

Starting OmniSharp server at 29/12/2020, 14:22:14 Target: d:\Secured\Code\project\repo\sample\build\sample.sln OmniSharp server started. Path: c:\Users\CHausner\.vscode\extensions\ms-dotnettools.csharp-1.23.8\.omnisharp\1.37.5\OmniSharp.exe PID: 16616 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: Visual Studio Community 2019 16.8.30804.86 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" 2: StandAlone 16.8.0 - "c:\Users\CHausner\.vscode\extensions\ms-dotnettools.csharp-1.23.8\.omnisharp\1.37.5\.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Community 2019 16.8.30804.86 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'd:\Secured\Code\project\repo\sample\build'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'd:\Secured\Code\project\repo\sample\build\sample.sln'. [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'd:\Secured\Code\project\repo\sample\build'. [info]: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'd:\Secured\Code\project\repo\sample\build' on host 16060.

Environment information

VSCode version: 1.52.1 C# Extension: 1.23.8

Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.101 Commit: d05174dc5a Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.101\ Host (useful for support): Version: 5.0.1 Commit: b02e13abab .NET SDKs installed: 1.1.11 [C:\Program Files\dotnet\sdk] 2.2.402 [C:\Program Files\dotnet\sdk] 5.0.101 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |cmake|twxs|0.0.17| |cmake-tools|ms-vscode|1.5.3| |cpptools|ms-vscode|1.1.3| |csharp|ms-dotnettools|1.23.8| |electron-debug|kodetech|18.11.1| |git-graph|mhutchie|1.28.0| |git-merger|shaharkazaz|0.4.1| |gitlens|eamodio|11.1.0| |gitstash|arturock|3.3.1| |hexeditor|ms-vscode|1.3.0| |jupyter|ms-toolsai|2020.12.414227025| |opensmile-config-files|chausner|1.4.0| |powershell|ms-vscode|2020.6.0| |python|ms-python|2020.12.424452561| |rainbow-csv|mechatroner|1.8.0| |remote-wsl|ms-vscode-remote|0.52.0| |vscode-catch2-test-adapter|matepek|3.6.19| |vscode-command-runner|edonet|0.0.116| |vscode-guid|heaths|1.4.20| |vscode-test-explorer|hbenl|2.19.3|;
JoeRobich commented 3 years ago

@chausner-audeering The C# extension lists *.sln as a trigger for loading the extension in VS Code. We should be smarter in this scenario, so that we do not keep the solution file open.

JoeRobich commented 3 years ago

As a workaround for this issue, you may want to consider disabling the C# extension for the workspace. image

chausner-audeering commented 3 years ago

As a workaround for this issue, you may want to consider disabling the C# extension for the workspace.

Thanks for that hint, I'll give it a try!