Skip to content

Commit

Permalink
Fix warning level calculation for .NET 10 (#45295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Dec 5, 2024
1 parent 5ad9226 commit f9cf0b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- The CSharp.props used to hard-code WarningLevel to 4, so to maintain parity with .NET Framework projects we do that here. -->
<WarningLevel Condition="'$(Language)' == 'C#' And '$(WarningLevel)' == '' And '$(TargetFrameworkIdentifier)' == '.NETFramework' ">4</WarningLevel>
<!-- .NET projects, however, can float up to their TFM's major version -->
<WarningLevel Condition="'$(Language)' == 'C#' And '$(WarningLevel)' == '' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">$(_TargetFrameworkVersionWithoutV.Substring(0, 1))</WarningLevel>
<WarningLevel Condition="'$(Language)' == 'C#' And '$(WarningLevel)' == '' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">$(_TargetFrameworkVersionWithoutV.Split('.')[0])</WarningLevel>
</PropertyGroup>

<!-- Enable Analyzers based on EffectiveAnalysisLevel -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public GivenThatWeWantToFloatWarningLevels(ITestOutputHelper log) : base(log)
}

[InlineData(targetFrameworkNet6, "6")]
[InlineData(ToolsetInfo.CurrentTargetFramework, "1")]
[InlineData(ToolsetInfo.CurrentTargetFramework, ToolsetInfo.CurrentTargetFrameworkVersion)]
[InlineData(targetFrameworkNetFramework472, "4")]
[RequiresMSBuildVersionTheory("16.8")]
public void It_defaults_WarningLevel_To_The_Current_TFM_When_Net(string tfm, string warningLevel)
Expand Down Expand Up @@ -59,7 +59,7 @@ static void Main()
}

[InlineData(1, "1")]
[InlineData(null, "1")]
[InlineData(null, ToolsetInfo.CurrentTargetFrameworkVersion)]
[RequiresMSBuildVersionTheory("16.8")]
public void It_always_accepts_user_defined_WarningLevel(int? warningLevel, string expectedWarningLevel)
{
Expand Down Expand Up @@ -156,8 +156,11 @@ static void Main()
buildResult.StdErr.Should().Be(string.Empty);
}

[InlineData(ToolsetInfo.CurrentTargetFramework, ToolsetInfo.CurrentTargetFrameworkVersion)]
[RequiresMSBuildVersionTheory("16.8")]
[InlineData(ToolsetInfo.CurrentTargetFramework, ToolsetInfo.NextTargetFrameworkVersion)]
// Fixing this test requires bumping _LatestAnalysisLevel and _PreviewAnalysisLevel
// Bumping will cause It_maps_analysis_properties_to_globalconfig to fail which requires changes in dotnet/roslyn-analyzers repo.
// See instructions in the comment in It_maps_analysis_properties_to_globalconfig
[RequiresMSBuildVersionTheory("16.8", Skip = "https://github.com/dotnet/sdk/issues/45299")]
public void It_defaults_preview_AnalysisLevel_to_the_next_tfm(string currentTFM, string nextTFMVersionNumber)
{
var testProject = new TestProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void It_warns_when_targeting_certain_frameworks_and_not_using_pragma_supp

[Theory]
[InlineData("net9.0")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
public void It_errors_when_targeting_certain_frameworks_and_not_using_pragma_suppressions(string targetFramework)
{
var testProject = new TestProject()
Expand All @@ -159,6 +160,7 @@ public void It_errors_when_targeting_certain_frameworks_and_not_using_pragma_sup

[Theory]
[InlineData("net9.0")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
public void It_allows_downgrading_errors_to_warnings_via_project_config(string targetFramework)
{
var testProject = new TestProject()
Expand Down

0 comments on commit f9cf0b9

Please sign in to comment.