Skip to content

[release/9.0.1xx] Add .NET 6.0 to End-of-Life frameworks list to generate NETSDK1138 warnings #49822

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

Open
wants to merge 6 commits into
base: release/9.0.1xx
Choose a base branch
from
Open
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 @@ -21,10 +21,10 @@ Copyright (c) .NET Foundation. All rights reserved.
receive servicing updates and security fixes.
-->
<ItemGroup>
<_EolNetCoreTargetFrameworkVersions Include="1.0;1.1;2.0;2.1;2.2;3.0;3.1;5.0;7.0" />
<_EolNetCoreTargetFrameworkVersions Include="1.0;1.1;2.0;2.1;2.2;3.0;3.1;5.0;6.0;7.0" />
</ItemGroup>
<PropertyGroup>
<_MinimumNonEolSupportedNetCoreTargetFramework>net6.0</_MinimumNonEolSupportedNetCoreTargetFramework>
<_MinimumNonEolSupportedNetCoreTargetFramework>net8.0</_MinimumNonEolSupportedNetCoreTargetFramework>
</PropertyGroup>

<Target Name="_CheckForEolTargetFrameworks" AfterTargets="_CheckForUnsupportedNETCoreVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public GivenThatWeWantToTargetEolFrameworks(ITestOutputHelper log) : base(log)
[InlineData("netcoreapp3.0")]
[InlineData("netcoreapp3.1")]
[InlineData("net5.0")]
[InlineData("net6.0")]
[InlineData("net7.0")]
public void It_warns_that_framework_is_out_of_support(string targetFrameworks)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,8 @@ public void PublishSingleFile_fails_for_unsupported_target_framework(string targ
[InlineData("net6.0", false)]
[InlineData("netstandard2.0;net5.0", true)] // None of these TFMs are supported for single-file
[InlineData("netstandard2.0;net6.0", false)] // Net6.0 is the min TFM supported for single-file and targeting.
[InlineData("netstandard2.0;net8.0", true)] // Net8.0 is supported for single-file, but leaves a "gap" for the supported net6./net7.0 TFMs.
[InlineData("netstandard2.0;net8.0", false)] // Net8.0 is supported for single-file
[InlineData("netstandard2.0;net9.0", true)] // Net9.0 is supported for single-file, but leaves a "gap" for the supported net6./net7.0 TFMs.
[InlineData("alias-ns2", true)]
[InlineData("alias-n6", false)]
[InlineData("alias-n6;alias-n8", false)] // If all TFMs are supported, there's no warning even though the project uses aliases.
Expand All @@ -744,18 +745,19 @@ public void EnableSingleFile_warns_when_expected_for_not_correctly_multitargeted
TargetFrameworks = targetFrameworks
};
testProject.AdditionalProperties["EnableSingleFileAnalyzer"] = "true";
testProject.AdditionalProperties["CheckEolTargetFramework"] = "false"; // Silence warning about targeting EOL TFMs
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFrameworks)
.WithProjectChanges(AddTargetFrameworkAliases);

var buildCommand = new BuildCommand(testAsset);
var resultAssertion = buildCommand.Execute("/bl:my.binlog")
var resultAssertion = buildCommand.Execute("/p:CheckEolTargetFramework=false")
.Should().Pass();
if (shouldWarn) {
// Note: can't check for Strings.EnableSingleFileAnalyzerUnsupported because each line of
// the message gets prefixed with a file path by MSBuild.
resultAssertion
.And.HaveStdOutContaining($"warning NETSDK1211")
.And.HaveStdOutContaining($"<EnableSingleFileAnalyzer Condition=\"$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))\">true</EnableSingleFileAnalyzer>");
.And.HaveStdOutContaining($"<EnableSingleFileAnalyzer Condition=\"$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))\">true</EnableSingleFileAnalyzer>");
} else {
resultAssertion.And.NotHaveStdOutContaining($"warning");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ public void PublishAot_fails_for_unsupported_target_framework(string targetFrame
[InlineData("net7.0", false)]
[InlineData("netstandard2.0;net5.0", true)] // None of these TFMs are supported for AOT
[InlineData("netstandard2.0;net7.0", false)] // Net7.0 is the min TFM supported for AOT and targeting.
[InlineData("netstandard2.0;net8.0", true)] // Net8.0 is supported for AOT, but leaves a "gap" for the supported net7.0 TFMs.
[InlineData("netstandard2.0;net8.0", false)] // net8.0 is supported for AOT and targeting.
[InlineData("netstandard2.0;net9.0", true)] // Net9.0 is supported for AOT, but leaves a "gap" for the supported net8.0 TFMs.
[InlineData("alias-ns2", true)]
[InlineData("alias-n6", true)]
[InlineData("alias-n7", false)]
Expand All @@ -646,18 +647,19 @@ public void IsAotCompatible_warns_when_expected_for_not_correctly_multitarget_li
TargetFrameworks = targetFrameworks
};
testProject.AdditionalProperties["IsAotCompatible"] = "true";
testProject.AdditionalProperties["CheckEolTargetFramework"] = "false"; // Silence warning about targeting EOL TFMs
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFrameworks)
.WithProjectChanges(AddTargetFrameworkAliases);

var buildCommand = new BuildCommand(testAsset);
var resultAssertion = buildCommand.Execute()
var resultAssertion = buildCommand.Execute("/p:CheckEolTargetFramework=false")
.Should().Pass();
if (shouldWarn) {
resultAssertion
// Note: can't check for Strings.IsAotCompatibleUnsupported because each line of
// the message gets prefixed with a file path by MSBuild.
.And.HaveStdOutContaining($"warning NETSDK1210")
.And.HaveStdOutContaining($"<IsAotCompatible Condition=\"$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))\">true</IsAotCompatible>");
.And.HaveStdOutContaining($"<IsAotCompatible Condition=\"$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))\">true</IsAotCompatible>");
} else {
resultAssertion.And.NotHaveStdOutContaining($"warning");
}
Expand Down
11 changes: 6 additions & 5 deletions test/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ public void PublishTrimmed_fails_for_unsupported_target_framework(string targetF
[InlineData("net5.0", true)]
[InlineData("net6.0", false)]
[InlineData("netstandard2.0;net5.0", true)] // None of these TFMs are supported for trimming
[InlineData("netstandard2.0;net6.0", false)] // Net6.0 is the min TFM supported for trimming and targeting.
[InlineData("netstandard2.0;net8.0", true)] // Net8.0 is supported for trimming, but leaves a "gap" for the supported net6.0/net7.0 TFMs.
[InlineData("netstandard2.0;net6.0", false)] // net6.0 is the min TFM supported for trimming and targeting.
[InlineData("netstandard2.0;net8.0", false)] // Net8.0 is supported for trimming and targeting.
[InlineData("netstandard2.0;net9.0", true)] // Net8.0 is supported for trimming, but leaves a "gap" for the supported net6.0/net7.0 TFMs.
[InlineData("alias-ns2", true)]
[InlineData("alias-n6", false)]
[InlineData("alias-n6;alias-n8", false)] // If all TFMs are supported, there's no warning even though the project uses aliases.
Expand All @@ -196,19 +197,19 @@ public void IsTrimmable_warns_when_expected_for_not_correctly_multitargeted_libr

var testProject = CreateTestProjectForILLinkTesting(targetFrameworks, projectName);
testProject.AdditionalProperties["IsTrimmable"] = "true";
testProject.AdditionalProperties["NoWarn"] = "NETSDK1138"; // Silence warning about targeting EOL TFMs
testProject.AdditionalProperties["CheckEolTargetFramework"] = "false"; // Silence warning about targeting EOL TFMs
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFrameworks)
.WithProjectChanges(AddTargetFrameworkAliases);

var buildCommand = new BuildCommand(testAsset);
var resultAssertion = buildCommand.Execute()
var resultAssertion = buildCommand.Execute("/p:CheckEolTargetFramework=false")
.Should().Pass();
if (shouldWarn) {
resultAssertion
// Note: can't check for Strings.IsTrimmableUnsupported because each line of
// the message gets prefixed with a file path by MSBuild.
.And.HaveStdOutContaining($"warning NETSDK1212")
.And.HaveStdOutContaining($"<IsTrimmable Condition=\"$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))\">true</IsTrimmable>");
.And.HaveStdOutContaining($"<IsTrimmable Condition=\"$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))\">true</IsTrimmable>");
} else {
resultAssertion.And.NotHaveStdOutContaining($"warning");
}
Expand Down
3 changes: 2 additions & 1 deletion test/dotnet-new.Tests/CommonTemplatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public async Task FeaturesSupport(
string finalProjectName = Path.Combine(projectDir, $"{projName}.{extension}");

Dictionary<string, string> environmentUnderTest = new() { ["DOTNET_NOLOGO"] = false.ToString() };
environmentUnderTest["CheckEolTargetFramework"] = false.ToString();
TestContext.Current.AddTestEnvironmentVariables(environmentUnderTest);

TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: name)
Expand Down Expand Up @@ -420,7 +421,7 @@ public async Task FeaturesSupport(
{
new DotnetBuildCommand(_log, "MyProject")
.WithWorkingDirectory(workingDir)
.Execute()
.Execute("/p:CheckEolTargetFramework=false")
.Should()
.Pass()
.And.NotHaveStdErr();
Expand Down
Loading