Repository: dotnet/roslyn-analyzers

Issue #6245: TargetFramework net7.0 disables all CAxxxx rules
Created: 2022-11-03T00:27:48Z
Just bumped my project to .NET 7.0 RC2 (running VS Version 17.4.0 Preview 6.0), and realized that all code analysis rules are disabled, no matter the settings. Downgrading the project to net6.0 re-enables all CAxxxx rules.
Steps To Reproduce
Just create a console project with some CAxxxx violations, and target net7.0. No warnings are produced. Downgrade to net6.0 to get the warnings back.
<PropertyGroup>
   <!--TargetFramework>net6.0</TargetFramework-->
   <TargetFramework>net7.0</TargetFramework>

   <OutputType>Exe</OutputType>
   <LangVersion>latest</LangVersion>
   <ImplicitUsings>enable</ImplicitUsings>
   <Nullable>enable</Nullable>
   <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
   <AnalysisMode>AllEnabledByDefault</AnalysisMode>
   <WarningLevel>9999</WarningLevel>
</PropertyGroup>

Expected behavior
CAxxxx rules are checked when targeting .NET 7.
Actual behavior
CAxxxx rules are checked only when targeting .NET 6 or earlier.

Duplicate issue #6263: Analyzers stopped working after upgrade to VS2022 17.4.0
Created: 2022-11-14T07:54:13Z
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 6.0.0
Describe the bug
Code Analysis was working fine with VS2022 version 17.3.4. After I upgraded to VS2022 version 17.4.0, CodeAnalysis stopped working completely, and I am not able to get it working again.
Steps To Reproduce

Have Visual Studio 2022 version 17.3.4 installed
Have a C# project that has the following in the project file (left out certain parts for brevity):

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net481</TargetFrameworks>
    <RootNamespace>MyRootNamespace</RootNamespace>
    <AssemblyName>MyAssembly</AssemblyName>
    <LangVersion>latest</LangVersion>
    <Nullable>disable</Nullable>
    <WarningLevel>4</WarningLevel>
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
    <AnalysisMode>All</AnalysisMode>
  </PropertyGroup>
  <!-- Left out additional properties -->
  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>


Make sure there are some code analysis issues in the code and build the project.
Upgrade to VS2022 version 17.4
Rebuild the project and notice none of the existing issues are reported anymore (though a warning is emitted indicating a newer version of the analyzers are available with the SDK).

Expected behavior
The code analysis keeps working, even after the upgrade.
Actual behavior
The code analysis is no longer performed.
Additional context
I have also tried the following to get the analysis working again, but all to no avail:

Completely remove the package reference to the Microsoft.CodeAnalysis.NetAnalyzers package. This removes the warning that a newer version is present in the SDK, but the code analysis is still not executed (at least no warnings/errors are emitted)
Replace the <AnalysisMode> property with the following: <EnableNETAnalyzers>True</EnableNETAnalyzers><AnalysisLevel>latest-all</AnalysisLevel>. This also does not make the code analysis emit any warnings/errors.
Replace the <PackageReference> with the latest version on NuGet (version 7.0.0-preview1.22518.1). This removes the warning that a newer version is present in the SDK, but the code analysis is still not executed (at least no warnings/errors are emitted)

Closing comment (2022-12-12T08:06:33Z): Thank you so much @MarcelVersteeg - I can reproduce the issue now. This is indeed a duplicate of #6245.
Tagging @jmarolf - Jon, your comment #6246 (comment) indicating that #6246 made it into .NET 7.0.100 SDK (and hence https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers/7.0.0) does not seem to be correct. I can confirm that by looking at the config files that ship inside the .NET 7.0.100 SDK, as well as 7.0.0 released NuGet package. The configs folder should have analysislevel_7_*.editorconfig files, but these are only present in 7.0.0-preview1.22559.1 package, not in the release 7.0.0 version or the SDK.
Config files in .NET 7.0.100 SDK

Config files in https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers/7.0.0

Config files in https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Microsoft.CodeAnalysis.NetAnalyzers/versions/7.0.0-preview1.22559.1

Adding an explicit NuGet package reference to latest 7.x.x preview package from this feed: https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Microsoft.CodeAnalysis.NetAnalyzers/versions/7.0.0-preview1.22559.1 as below fixes the issue: <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22559.1">