dotnet / vscode-csharp

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

OmniSharp giving explicitly disabled warnings #5115

Open RivenSkaye opened 2 years ago

RivenSkaye commented 2 years ago

Issue Description

I'm working on a legacy project, which was written for an old .NET Framework version and thus doesn't support newer language features such as simple using statements and target-typed new() expressions.

Already tried not overriding the MSBuild being selected for this project, but it doesn't change the warnings still getting emitted. Still, mandatory snippet from the startup log: `[warn]: OmniSharp.CompositionHostBuilder It looks like you have overridden the version of MSBuild with a version lower than 16.3 which is the minimum supported by the configured .NET Core Sdk. Try updating your MSBuild to version 16.3 or higher to enable better .NET Core Sdk support.

    Registered MSBuild instance: Proper MSBuild 15.9.21 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"`

Steps to Reproduce

Open old .NET 3.5 Framework project, turn the relevant warnings off and do something like

using (OleDbCommand updateCmd = new OleDbCommand(query, conn))
{
    int res = updateCmd.ExecuteNonQuery();
    if (res < 0)
    {
        LogDbErr(update, somedata, LogLevel.Error);
    }
}

That produces both of the info flags at once. Just doing OleDbCommand updateCmd = new OleDbCommand(query, conn) on a line of its own makes it present the new expression can be simplified warning just as well.

In the .editorconfig I put in the root of the folder I set the project formatting options and they all work, but there's two entries being ignored:

csharp_prefer_simple_using_statement = false
csharp_style_implicit_object_creation_when_type_is_apparent = false

Expected Behavior

No warnings about disabled new language features because checking for them is disabled.

Actual Behavior

Get a lot of noise in my warnings with the report state of the two warnings is set to false. Also tried false:none and false:silent to no effect

Environment information

VSCode version: 1.65.2 C# Extension: 1.24.1

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.201 Commit: ef40e6aa06 Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.201\ Host (useful for support): Version: 6.0.3 Commit: c24d9a9c91 .NET SDKs installed: 6.0.201 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.3 [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| |---|---|---| |auto-close-tag|formulahendry|0.5.14| |cpptools|ms-vscode|1.8.4| |csharp|ms-dotnettools|1.24.1| |EditorConfig|EditorConfig|0.16.4| |msbuild-project-tools|tintoy|0.4.3| |remote-containers|ms-vscode-remote|0.224.3| |remotehub|GitHub|0.26.0| |vscode-docker|ms-azuretools|1.20.0| |vscodeintellicode|VisualStudioExptTeam|1.2.17| |xml|DotJoshJohnson|2.5.1|; Omitted a couple extensions like Rust, Python and Perl stuff, since they error and exit on this office machine that doesn't have my dev env installed
nohwnd commented 2 years ago

@333fred Could you have a look on this one, please?

RivenSkaye commented 2 years ago

Update: Mangling the .csproj file and adding the <Langversion> and explicitly setting it to 7.3 seems to be resolving the issue. This indicates that either OmniSharp or Roslyn isn't processing the <TargetFrameworkVersion> the same way as when running the compiler.

Seems like the original project is also old enough that <LangVersion> was either not included by default, or did not yet exist. I have no idea when that tag is from though.