dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 669 forks source link

Circular dependency between project restore and open, forcing to restore via the terminal. #4694

Open jesperkristensen opened 3 years ago

jesperkristensen commented 3 years ago

Issue Description

Sometimes VS Code cannot open a solution before it has been restored, and VS Code cannot restore a solution before it has been opened. So I have to navigate to the solution in a terminal and run the dotnet restore command from there before I can open it.

Steps to Reproduce

  1. git pull an update where a team member added a new nuget dependency.
  2. Open the .sln file with "OmniSharp: Select Project".
  3. An error message says that not all projects in the solution could be loaded. the OmniSharp log indicated that these projects need to be restored first.
  4. Use ".NET: Restore All Projects".
  5. It attempts to restore the projects in the solution that were already restored. It does not attempt to restore projects that were not restored.

Expected Behavior

"OmniSharp: Select Project" should open all projects in the .sln file no matter if they were already restored or not, such that a subsequent ".NET: Restore All Projects" command would include all the projects.

Actual Behavior

Need to open a terminal and run dotnet restore ****.sln before using "OmniSharp: Select Project"

Logs

OmniSharp log

    Failed to load project file '****.csproj'.

****.csproj C:\Program Files\dotnet\sdk\5.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): Error: Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.14 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.58.2 C# Extension: 1.23.14

Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.302 Commit: c005824e35 Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.302\ Host (useful for support): Version: 5.0.8 Commit: 35964c9215 .NET SDKs installed: 3.1.407 [C:\Program Files\dotnet\sdk] 5.0.201 [C:\Program Files\dotnet\sdk] 5.0.302 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.8 [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| |---|---|---| |azure-account|ms-vscode|0.9.8| |azure-pipelines|ms-azure-devops|1.188.1| |azurecli|ms-vscode|0.5.0| |azurite|Azurite|3.14.0| |csharp|ms-dotnettools|1.23.14| |docomment|k--kato|0.1.20| |dotnet-interactive-vscode|ms-dotnettools|1.0.2357010| |EditorConfig|EditorConfig|0.16.4| |git-graph|mhutchie|1.30.0| |gitlens|eamodio|11.6.0| |jupyter|ms-toolsai|2021.8.1054968649| |markdown-all-in-one|yzhang|3.4.0| |todo-tree|Gruntfuggly|0.0.213| |user-secrets|adrianwilczynski|2.0.1| |uuid-generator|netcorext|0.0.4| |vscode-azurefunctions|ms-azuretools|1.4.1| |vscode-azureresourcegroups|ms-azuretools|0.4.0| |vscode-azurestorage|ms-azuretools|0.12.1| |vscode-bicep|ms-azuretools|0.4.451| |vscode-dotnet-runtime|ms-dotnettools|1.2.0|;
JoeRobich commented 3 years ago

One work around is to add a global omnisharp configuration file located in %USERPROFILE%/.omnisharp/ which enables the automatic package restore option (See https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options)

{
  "msbuild": {
     "EnablePackageAutoRestore" : true
  }
}