Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning level calculation for .NET 10 #45295

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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