Skip to content

Commit f9cf0b9

Browse files
authored
Fix warning level calculation for .NET 10 (#45295)
Fixes dotnet/roslyn#76226
1 parent 5ad9226 commit f9cf0b9

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Copyright (c) .NET Foundation. All rights reserved.
6262
<!-- The CSharp.props used to hard-code WarningLevel to 4, so to maintain parity with .NET Framework projects we do that here. -->
6363
<WarningLevel Condition="'$(Language)' == 'C#' And '$(WarningLevel)' == '' And '$(TargetFrameworkIdentifier)' == '.NETFramework' ">4</WarningLevel>
6464
<!-- .NET projects, however, can float up to their TFM's major version -->
65-
<WarningLevel Condition="'$(Language)' == 'C#' And '$(WarningLevel)' == '' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">$(_TargetFrameworkVersionWithoutV.Substring(0, 1))</WarningLevel>
65+
<WarningLevel Condition="'$(Language)' == 'C#' And '$(WarningLevel)' == '' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">$(_TargetFrameworkVersionWithoutV.Split('.')[0])</WarningLevel>
6666
</PropertyGroup>
6767

6868
<!-- Enable Analyzers based on EffectiveAnalysisLevel -->

test/Microsoft.NET.Build.Tests/GivenThatWeWantToFloatWarningLevels.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public GivenThatWeWantToFloatWarningLevels(ITestOutputHelper log) : base(log)
1313
}
1414

1515
[InlineData(targetFrameworkNet6, "6")]
16-
[InlineData(ToolsetInfo.CurrentTargetFramework, "1")]
16+
[InlineData(ToolsetInfo.CurrentTargetFramework, ToolsetInfo.CurrentTargetFrameworkVersion)]
1717
[InlineData(targetFrameworkNetFramework472, "4")]
1818
[RequiresMSBuildVersionTheory("16.8")]
1919
public void It_defaults_WarningLevel_To_The_Current_TFM_When_Net(string tfm, string warningLevel)
@@ -59,7 +59,7 @@ static void Main()
5959
}
6060

6161
[InlineData(1, "1")]
62-
[InlineData(null, "1")]
62+
[InlineData(null, ToolsetInfo.CurrentTargetFrameworkVersion)]
6363
[RequiresMSBuildVersionTheory("16.8")]
6464
public void It_always_accepts_user_defined_WarningLevel(int? warningLevel, string expectedWarningLevel)
6565
{
@@ -156,8 +156,11 @@ static void Main()
156156
buildResult.StdErr.Should().Be(string.Empty);
157157
}
158158

159-
[InlineData(ToolsetInfo.CurrentTargetFramework, ToolsetInfo.CurrentTargetFrameworkVersion)]
160-
[RequiresMSBuildVersionTheory("16.8")]
159+
[InlineData(ToolsetInfo.CurrentTargetFramework, ToolsetInfo.NextTargetFrameworkVersion)]
160+
// Fixing this test requires bumping _LatestAnalysisLevel and _PreviewAnalysisLevel
161+
// Bumping will cause It_maps_analysis_properties_to_globalconfig to fail which requires changes in dotnet/roslyn-analyzers repo.
162+
// See instructions in the comment in It_maps_analysis_properties_to_globalconfig
163+
[RequiresMSBuildVersionTheory("16.8", Skip = "https://github.com/dotnet/sdk/issues/45299")]
161164
public void It_defaults_preview_AnalysisLevel_to_the_next_tfm(string currentTFM, string nextTFMVersionNumber)
162165
{
163166
var testProject = new TestProject

test/Microsoft.NET.Build.Tests/GivenThatWeWantToUseBinaryFormatter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void It_warns_when_targeting_certain_frameworks_and_not_using_pragma_supp
133133

134134
[Theory]
135135
[InlineData("net9.0")]
136+
[InlineData(ToolsetInfo.CurrentTargetFramework)]
136137
public void It_errors_when_targeting_certain_frameworks_and_not_using_pragma_suppressions(string targetFramework)
137138
{
138139
var testProject = new TestProject()
@@ -159,6 +160,7 @@ public void It_errors_when_targeting_certain_frameworks_and_not_using_pragma_sup
159160

160161
[Theory]
161162
[InlineData("net9.0")]
163+
[InlineData(ToolsetInfo.CurrentTargetFramework)]
162164
public void It_allows_downgrading_errors_to_warnings_via_project_config(string targetFramework)
163165
{
164166
var testProject = new TestProject()

0 commit comments

Comments
 (0)