简体   繁体   中英

How to made VSCode compatible with ImplicitUsings in dotnet 7?

I am trying to use VSCode on my Linux laptop to develop a do.net7 WebAPI Application. So, the vs code version is: 1.74.3 , and the .Net Extension Pack is installed on my VSCode.

Also, the C# extension (powered by OmniSharp) v1.25.4 is installed. Nut when I create my application using do.net new webapi and open the folder using VSCode, the Implicite Usings aren't recognized and codes are shown with a red stroke.

but my project builds successfully and run without any problems. It seems that the VSCode Intellisense is not compatible with the new C# conventions. How cloud I get rid of these fake error indicators?

在此处输入图像描述


here are my OmniSharp server logs:

Starting OmniSharp server at 1/31/2023, 9:05:49 PM
    Target: /home/navid/Desktop/dotnetTest

OmniSharp server started with .NET 7.0.101
 (/usr/share/dotnet).
    Path: /home/navid/.vscode/extensions/ms-dotnettools.csharp-1.25.4-linux-x64/.omnisharp/1.39.4-net6.0/OmniSharp.dll
    PID: 111338


[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 6.0.404 17.3.2 - "/usr/share/dotnet/sdk/6.0.404/"
            2: .NET SDK 6.0.404 from /usr/share/dotnet/sdk/6.0.404 6.0.404 - "/usr/share/dotnet/sdk/6.0.404"

[warn]: OmniSharp.CompositionHostBuilder
        It looks like you have overridden the version of MSBuild with a version lower than 16.8.0 which is the minimum supported by the configured .NET Core Sdk.
 Try updating your MSBuild to version 16.8.0 or higher to enable better .NET Core Sdk support.

[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: .NET SDK 6.0.404 from /usr/share/dotnet/sdk/6.0.404 6.0.404 - "/usr/share/dotnet/sdk/6.0.404"

[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0

[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/navid/Desktop/dotnetTest'.

[info]: OmniSharp.Cake.CakeProjectSystem
        Did not find any Cake files

[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in '/home/navid/Desktop/dotnetTest'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/navid/Desktop/dotnetTest/dotnetTest.csproj'

[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/navid/Desktop/dotnetTest'.

[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 '/home/navid/Desktop/dotnetTest' on host 111000.

[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/navid/Desktop/dotnetTest/dotnetTest.csproj

[warn]: OmniSharp.MSBuild.ProjectLoader
        You are running the 'restore' operation with an 'HTTP' source, 'http://nexus.xaniis.local/repository/nuget-hosted/'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.

[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
        No document found. File: /home/navid/Desktop/dotnetTest/Controllers/WeatherForecastController.cs.

[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/home/navid/Desktop/dotnetTest/dotnetTest.csproj'.
/home/navid/Desktop/dotnetTest/dotnetTest.csproj
/home/navid/Desktop/dotnetTest/dotnetTest.csproj(0,0): Error: You are running the 'restore' operation with an 'HTTP' source, 'http://nexus.xaniis.local/repository/nuget-hosted/'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.

[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/home/navid/Desktop/dotnetTest/dotnetTest.csproj'

[info]: OmniSharp.MSBuild.ProjectManager
        Update project: dotnetTest
Received response for /findusages but could not find request.
Received response for /findusages but could not find request.

this is my csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
  </ItemGroup>

</Project>

And Also this is my do.net --list-sdks

5.0.404 [/usr/share/do.net/sdk]

6.0.101 [/usr/share/do.net/sdk]

6.0.404 [/usr/share/do.net/sdk]

7.0.101 [/usr/share/do.net/sdk]

I found the solution, I had to change the SDK directory of the OmniSharp from V6 to v7.

It is accessible by this key inside the VSCode setting: omnisharp.sdkPath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM