dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 654 forks source link

Omnisharp redlines NET 6 packages and code after NET 7 installation MacOS 12.6 #5463

Open washeduplizard opened 1 year ago

washeduplizard commented 1 year ago

Issue Description

NET 7 installation makes omnisharp redline AspNetCore packages on previous .NET sdks on MacOS+VSCode

Steps to Reproduce

Have .NET 7 installed on machine Open Project or solution in VSCode running .NET 6 project or solution will restore and build successfully but code and packages will be redlined

Expected Behavior

Omnisharp should not redline

Actual Behavior

Screenshot 2022-11-16 at 15 19 58

Logs

OmniSharp log

Starting OmniSharp server at 11/16/2022, 3:30:56 PM Target: /Users/dkTimVer/Projects/Lego/mould-log-api/LEGO.MouldLog.sln OmniSharp server started with .NET 7.0.100 . Path: /Users/dkTimVer/.vscode/extensions/ms-dotnettools.csharp-1.25.2-darwin-x64/.omnisharp/1.39.3-beta.11-net6.0/OmniSharp.dll PID: 6468 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Unknown 0.0 (Unknown) [info]: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK [info]: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: .NET Core SDK 7.0.100 17.4.0 - "/usr/local/share/dotnet/sdk/7.0.100/" 2: .NET Core SDK 6.0.201 17.1.0 - "/usr/local/share/dotnet/sdk/6.0.201/" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: .NET Core SDK 7.0.100 17.4.0 - "/usr/local/share/dotnet/sdk/7.0.100/" [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in '/Users/dkTimVer/Projects/Lego/mould-log-api'. [info]: OmniSharp.Cake.CakeProjectSystem Did not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in '/Users/dkTimVer/Projects/Lego/mould-log-api/LEGO.MouldLog.sln'. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/api/LEGO.MouldLog.Api.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/api-e2e-tests/LEGO.MouldLog.Api.Tests.E2E.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/api-unit-tests/LEGO.MouldLog.Api.Tests.Unit.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/domain/LEGO.MouldLog.Domain.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/domain-unit-tests/LEGO.MouldLog.Domain.Tests.Unit.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/ErrorCauseAPI/src/LEGO.ErrorCauseAPI/LEGO.ErrorCauseAPI.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/InspectionCatalogCode/src/LEGO.SAP.InspectionCatalogCode/LEGO.SAP.InspectionCatalogCode.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/Notification/src/LEGO.SAP.Notification/LEGO.SAP.Notification.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/Users/dkTimVer/Projects/Lego/mould-log-api'. [info]: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/Users/dkTimVer/Projects/Lego/mould-log-api' on host 6158. [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/api/LEGO.MouldLog.Api.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/api/LEGO.MouldLog.Api.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/api/LEGO.MouldLog.Api.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/api-e2e-tests/LEGO.MouldLog.Api.Tests.E2E.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/api-e2e-tests/LEGO.MouldLog.Api.Tests.E2E.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/api-e2e-tests/LEGO.MouldLog.Api.Tests.E2E.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/api-unit-tests/LEGO.MouldLog.Api.Tests.Unit.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/api-unit-tests/LEGO.MouldLog.Api.Tests.Unit.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/api-unit-tests/LEGO.MouldLog.Api.Tests.Unit.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/domain/LEGO.MouldLog.Domain.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/domain/LEGO.MouldLog.Domain.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/domain/LEGO.MouldLog.Domain.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/domain-unit-tests/LEGO.MouldLog.Domain.Tests.Unit.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/domain-unit-tests/LEGO.MouldLog.Domain.Tests.Unit.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/domain-unit-tests/LEGO.MouldLog.Domain.Tests.Unit.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/ErrorCauseAPI/src/LEGO.ErrorCauseAPI/LEGO.ErrorCauseAPI.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/ErrorCauseAPI/src/LEGO.ErrorCauseAPI/LEGO.ErrorCauseAPI.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/ErrorCauseAPI/src/LEGO.ErrorCauseAPI/LEGO.ErrorCauseAPI.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/InspectionCatalogCode/src/LEGO.SAP.InspectionCatalogCode/LEGO.SAP.InspectionCatalogCode.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/InspectionCatalogCode/src/LEGO.SAP.InspectionCatalogCode/LEGO.SAP.InspectionCatalogCode.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/InspectionCatalogCode/src/LEGO.SAP.InspectionCatalogCode/LEGO.SAP.InspectionCatalogCode.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/Notification/src/LEGO.SAP.Notification/LEGO.SAP.Notification.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/Notification/src/LEGO.SAP.Notification/LEGO.SAP.Notification.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/Users/dkTimVer/Projects/Lego/mould-log-api/generated-clients/Notification/src/LEGO.SAP.Notification/LEGO.SAP.Notification.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.MouldLog.Api [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.MouldLog.Api.Tests.E2E [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.MouldLog.Api.Tests.Unit [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.MouldLog.Domain [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.MouldLog.Domain.Tests.Unit [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.ErrorCauseAPI [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.SAP.InspectionCatalogCode [info]: OmniSharp.MSBuild.ProjectManager Update project: LEGO.SAP.Notification [info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers Solution initialized -> queue all documents for code analysis. Initial document count: 225. Received response for /quickinfo but could not find request. Received response for /v2/getcodeactions but could not find request. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /Users/dkTimVer/Projects/Lego/mould-log-api/api/Controllers/V1/EntriesController.cs, Line: 17, Column: 47. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request.

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.73.1 C# Extension: 1.25.2

Mono Information OmniSharp using mono: 6.12.0
Dotnet Information .NET SDK: Version: 7.0.100 Commit: e12b7af219 Runtime Environment: OS Name: Mac OS X OS Version: 12.6 OS Platform: Darwin RID: osx.12-x64 Base Path: /usr/local/share/dotnet/sdk/7.0.100/ Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4 .NET SDKs installed: 3.1.416 [/usr/local/share/dotnet/sdk] 3.1.417 [/usr/local/share/dotnet/sdk] 5.0.405 [/usr/local/share/dotnet/sdk] 5.0.406 [/usr/local/share/dotnet/sdk] 6.0.201 [/usr/local/share/dotnet/sdk] 7.0.100 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.23 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.22 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |angular-schematics|cyrilletuzi|5.2.8| |auto-barrel|mikehanson|1.10.0| |code-spell-checker|streetsidesoftware|2.11.0| |csharp|ms-dotnettools|1.25.2| |csharpextensions|kreativ-software|1.7.3| |csharpier-vscode|csharpier|1.3.5| |data-workspace-vscode|ms-mssql|0.3.0| |dotnet-test-explorer|formulahendry|0.7.8| |EditorConfig|EditorConfig|0.16.4| |intellicode-api-usage-examples|VisualStudioExptTeam|0.2.6| |java|redhat|1.12.0| |mssql|ms-mssql|1.16.0| |ng-template|Angular|14.2.0| |ng-zorro-vscode|cipchk|14.0.2| |powershell|ms-vscode|2022.10.0| |prettier-vscode|esbenp|9.9.0| |remote-containers|ms-vscode-remote|0.262.3| |sort-js-object-keys|zengxingxin|1.0.6| |sql-bindings-vscode|ms-mssql|0.3.0| |sql-database-projects-vscode|ms-mssql|0.19.0| |user-secrets|adrianwilczynski|2.0.1| |vscode-docker|ms-azuretools|1.22.2| |vscode-eslint|dbaeumer|2.2.6| |vscode-java-debug|vscjava|0.46.0| |vscode-java-dependency|vscjava|0.21.1| |vscode-java-pack|vscjava|0.25.6| |vscode-java-test|vscjava|0.37.1| |vscode-kubernetes-tools|ms-kubernetes-tools|1.3.11| |vscode-lombok|vscjava|1.1.0| |vscode-maven|vscjava|0.39.2| |vscode-mysql|formulahendry|0.4.1| |vscode-pull-request-github|GitHub|0.54.1| |vscode-structurizr|ciarant|0.0.9| |vscode-stylelint|stylelint|1.2.3| |vscode-typescript-tslint-plugin|ms-vscode|1.3.4| |vscode-yaml|redhat|1.10.1| |vscodeintellicode|VisualStudioExptTeam|1.2.29|;
filipw commented 1 year ago

Have you tried dotnet clean and dotnet build after installing the new SDK?

washeduplizard commented 1 year ago

Yes, I have. Retried just now as well for good measure but to no avail.

tillig commented 1 year ago

I see this as well. I don't see any relevant logs in the OmniSharp window, but I do see it's finding both .NET 6 and 7. I'll include logs below.

If I update global.json to specify .NET 7 SDK and update the list of target frameworks to include net7.0 this goes away, but just one or the other doesn't fix it.

I tried dotnet clean and dotnet build, it didn't fix the issue.

Logs from OmniSharp, if it helps. This is a project where global.json specifies .NET 6.0.401 (which is installed) and the target framework is only net6.0.

Starting OmniSharp server at 11/18/2022, 9:32:56 AM
    Target: /Users/tillig/dev/my-project/MyProject.sln

OmniSharp server started with .NET 6.0.401
.
    Path: /Users/tillig/.vscode/extensions/ms-dotnettools.csharp-1.25.2-darwin-x64/.omnisharp/1.39.2-net6.0/OmniSharp.dll
    PID: 46837

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Unknown 0.0 (Unknown)
[info]: OmniSharp.Services.DotNetCliService
        Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
        Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: .NET Core SDK 7.0.100 17.4.0 - "/usr/local/share/dotnet/sdk/7.0.100/"
            2: .NET Core SDK 6.0.401 17.3.1 - "/usr/local/share/dotnet/sdk/6.0.401/"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: .NET Core SDK 7.0.100 17.4.0 - "/usr/local/share/dotnet/sdk/7.0.100/"
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
BritoAlv commented 1 year ago

Same problem, any hint?

davemateer commented 1 year ago

Also seeing this same problem. Cannot use VS Code for .Net 6 projects after installing .Net 7 SDK. Uninstalling the .Net 7 SDK resolves the problem.

davemateer commented 1 year ago

And the real kicker is until OmniSharp.SdkInstanceProvider fails to parse 'omnisharp.sdkVersion' and 'omnisharp.sdkPath' is fixed, I think maybe the only solution is to keep uninstalling the SDK for .Net 6 and then reinstalling when working on a .Net 7 project.

filipw commented 1 year ago

And the real kicker is until OmniSharp.SdkInstanceProvider fails to parse 'omnisharp.sdkVersion' and 'omnisharp.sdkPath' is fixed, I think maybe the only solution is to keep uninstalling the SDK for .Net 6 and then reinstalling when working on a .Net 7 project.

I am sorry for your trouble. The handling of these properties was fixed already but the patched extension has not been released yet. However, there are other ways of telling OmniSharp which SDK to use than just using the VS Code options.

You can create a file omnisharp.json and set:

{
    "sdk": {
        "path": "/usr/local/share/dotnet/sdk/6.0.403/",
        "version": "6.0.403"
    }
}

in it. The file can be placed in the root directory of your solution (then it applies only there) or in %USERPROFILE%/.omnisharp/omnisharp.json, then it applies globally.

See here for more details https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options#sdk-options