From 1efd3513edadb44da70cb05283157f08c58803c6 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Mon, 17 Oct 2022 11:35:49 +0200 Subject: [PATCH] (GH-3950) Add .NET 7 Support * fixes #3950 --- .github/workflows/build.yml | 5 ++++ build.cake | 5 ++-- global.json | 2 +- src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs | 22 +++++++++++++- src/Cake.Core/Scripting/ScriptConventions.cs | 3 ++ src/Cake.NuGet/Cake.NuGet.csproj | 2 +- src/Cake/Cake.csproj | 7 +++-- .../Scripting/ReferenceAssemblyResolver.cs | 4 ++- src/Shared.msbuild | 6 ++-- .../ValidateGitHubActionsProvider.cake | 4 ++- .../Cake.Core/Scripting/AddinDirective.cake | 22 +++++++++----- .../Cake.Core/Scripting/DefineDirective.cake | 30 ++++++++++++++++--- .../Cake.Frosting/build/Build.csproj | 2 +- 13 files changed, 89 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2665b3b2c8..6dc34357cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,11 @@ jobs: with: dotnet-version: '5.0.x' + - name: Install .NET SDK 6.0.x + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + - name: Install .NET Core SDK (global.json) uses: actions/setup-dotnet@v1 with: diff --git a/build.cake b/build.cake index 90caf16368..a23babdc0b 100644 --- a/build.cake +++ b/build.cake @@ -123,7 +123,7 @@ Task("Run-Unit-Tests") () => GetFiles("./src/**/*.Tests.csproj"), (parameters, project, context) => { - foreach(var framework in new[] { "netcoreapp3.1", "net5.0", "net6.0" }) + foreach(var framework in new[] { "netcoreapp3.1", "net5.0", "net6.0", "net7.0" }) { FilePath testResultsPath = MakeAbsolute(parameters.Paths.Directories.TestResults .CombineWithFilePath($"{project.GetFilenameWithoutExtension()}_{framework}_TestResults.xml")); @@ -392,7 +392,8 @@ Task("Run-Integration-Tests") parameters => new[] { GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/netcoreapp3.1/**/Cake.dll").Single(), GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net5.0/**/Cake.dll").Single(), - GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net6.0/**/Cake.dll").Single() + GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net6.0/**/Cake.dll").Single(), + GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net7.0/**/Cake.dll").Single() }, (parameters, cakeAssembly, context) => { diff --git a/global.json b/global.json index 8b559ba7ba..b611e15f94 100644 --- a/global.json +++ b/global.json @@ -3,7 +3,7 @@ "src" ], "sdk": { - "version": "6.0.402", + "version": "7.0.100-rc.2.22477.23", "rollForward": "latestFeature" } } \ No newline at end of file diff --git a/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs b/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs index 21aad8bf1e..65cb681b09 100644 --- a/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs +++ b/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs @@ -39,7 +39,9 @@ public void Should_Return_Correct_Result_For_CoreClr() Assert.Equal(".NETStandard,Version=v2.0", framework.FullName); #else var expect = string.Concat(".NETCoreApp,Version=v", -#if NET6_0 +#if NET7_0 + "7.0"); +#elif NET6_0 "6.0"); #elif NET5_0 "5.0"); @@ -66,6 +68,7 @@ public void Should_Return_Correct_Result_For_CoreClr() case ".NETCoreApp,Version=v3.1": case ".NETCoreApp,Version=v5.0": case ".NETCoreApp,Version=v6.0": + case ".NETCoreApp,Version=v7.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -82,6 +85,7 @@ public void Should_Return_Correct_Result_For_CoreClr() case ".NETCoreApp,Version=v3.1": case ".NETCoreApp,Version=v5.0": case ".NETCoreApp,Version=v6.0": + case ".NETCoreApp,Version=v7.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -97,6 +101,7 @@ public void Should_Return_Correct_Result_For_CoreClr() case ".NETCoreApp,Version=v3.1": case ".NETCoreApp,Version=v5.0": case ".NETCoreApp,Version=v6.0": + case ".NETCoreApp,Version=v7.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -111,6 +116,7 @@ public void Should_Return_Correct_Result_For_CoreClr() { case ".NETCoreApp,Version=v5.0": case ".NETCoreApp,Version=v6.0": + case ".NETCoreApp,Version=v7.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -124,6 +130,20 @@ public void Should_Return_Correct_Result_For_CoreClr() switch (framework.FullName) { case ".NETCoreApp,Version=v6.0": + case ".NETCoreApp,Version=v7.0": + { + TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); + expect = framework.FullName; + break; + } + } + break; + } + case ".NETCoreApp,Version=v6.0": + { + switch (framework.FullName) + { + case ".NETCoreApp,Version=v7.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; diff --git a/src/Cake.Core/Scripting/ScriptConventions.cs b/src/Cake.Core/Scripting/ScriptConventions.cs index dea181f53f..91d6115467 100644 --- a/src/Cake.Core/Scripting/ScriptConventions.cs +++ b/src/Cake.Core/Scripting/ScriptConventions.cs @@ -122,6 +122,9 @@ private string GetFrameworkDefine() case ".NETCoreApp,Version=v6.0": return "NET6_0"; + case ".NETCoreApp,Version=v7.0": + return "NET7_0"; + default: Console.Error.WriteLine(_runtime.BuiltFramework.FullName); Console.Error.Flush(); diff --git a/src/Cake.NuGet/Cake.NuGet.csproj b/src/Cake.NuGet/Cake.NuGet.csproj index 44fccf8e9b..9bfd900963 100644 --- a/src/Cake.NuGet/Cake.NuGet.csproj +++ b/src/Cake.NuGet/Cake.NuGet.csproj @@ -29,7 +29,7 @@ - + All diff --git a/src/Cake/Cake.csproj b/src/Cake/Cake.csproj index db6f8b58d5..ab43e32f64 100644 --- a/src/Cake/Cake.csproj +++ b/src/Cake/Cake.csproj @@ -26,10 +26,11 @@ - - - + + + + diff --git a/src/Cake/Infrastructure/Scripting/ReferenceAssemblyResolver.cs b/src/Cake/Infrastructure/Scripting/ReferenceAssemblyResolver.cs index 843316378d..80d032f250 100644 --- a/src/Cake/Infrastructure/Scripting/ReferenceAssemblyResolver.cs +++ b/src/Cake/Infrastructure/Scripting/ReferenceAssemblyResolver.cs @@ -26,8 +26,10 @@ IEnumerable TryGetReferenceAssemblies() Basic.Reference.Assemblies.NetCoreApp31.All) #elif NET5_0 Basic.Reference.Assemblies.Net50.All) -#else +#elif NET6_0 Basic.Reference.Assemblies.Net60.All) +#else + Basic.Reference.Assemblies.Net70.All) #endif { Assembly assembly; diff --git a/src/Shared.msbuild b/src/Shared.msbuild index 3e654f3d3e..69c2b60e18 100644 --- a/src/Shared.msbuild +++ b/src/Shared.msbuild @@ -1,7 +1,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net5.0;net6.0;net7.0 $(AssemblyName) Copyright (c) .NET Foundation and contributors Patrik Svensson, Mattias Karlsson, Gary Ewan Park, Alistair Chapman, Martin Björkström, Dave Glick, Pascal Berger, Jérémie Desautels, Enrico Campidoglio, C. Augusto Proiete, Nils Andresen, and contributors @@ -12,12 +12,12 @@ git Cake;Script;Build https://cakebuild.net - 8.0 + 9.0 NuGet.org.md - + 2.0.0 $(DefineConstants);NETCORE portable diff --git a/tests/integration/Cake.Common/Build/GitHubActions/ValidateGitHubActionsProvider.cake b/tests/integration/Cake.Common/Build/GitHubActions/ValidateGitHubActionsProvider.cake index 852ae63fe6..25c014671b 100644 --- a/tests/integration/Cake.Common/Build/GitHubActions/ValidateGitHubActionsProvider.cake +++ b/tests/integration/Cake.Common/Build/GitHubActions/ValidateGitHubActionsProvider.cake @@ -16,7 +16,8 @@ Task("ValidateEnvironment") data => new [] { $"CAKE_{data.OS}_NETCOREAPP_3_1_VERSION", $"CAKE_{data.OS}_NETCOREAPP_5_0_VERSION", - $"CAKE_{data.OS}_NETCOREAPP_6_0_VERSION" + $"CAKE_{data.OS}_NETCOREAPP_6_0_VERSION", + $"CAKE_{data.OS}_NETCOREAPP_7_0_VERSION" }, (data, envKey) => Assert.Equal(data.GitVersion, EnvironmentVariable(envKey)) ); @@ -24,6 +25,7 @@ Task("ValidateEnvironment") Task("ValidatePath") .DoesForEach( new [] { + "Cake\\WTool\\Wtools\\Wnet7\\W0", "Cake\\WTool\\Wtools\\Wnet6\\W0", "Cake\\WTool\\Wtools\\Wnet5\\W0", "Cake\\WTool\\Wtools\\Wnetcoreapp3\\W1" diff --git a/tests/integration/Cake.Core/Scripting/AddinDirective.cake b/tests/integration/Cake.Core/Scripting/AddinDirective.cake index bc0f3c831a..a6d7f5847c 100644 --- a/tests/integration/Cake.Core/Scripting/AddinDirective.cake +++ b/tests/integration/Cake.Core/Scripting/AddinDirective.cake @@ -1,4 +1,6 @@ -#addin nuget:?package=Cake.Kudu.Client&version=0.9.0 +#addin nuget:?package=Cake.Kudu.Client&version=2.0.0 +#load "./../../utilities/paths.cake" + Task("Cake.Core.Scripting.AddinDirective.LoadTargetedAddin") .Does(() => @@ -8,9 +10,14 @@ Task("Cake.Core.Scripting.AddinDirective.LoadTargetedAddin") FilePath cakeCore = typeof(ICakeContext).GetTypeInfo().Assembly.Location; FilePath cake = cakeCore.GetDirectory().CombineWithFilePath("Cake.dll"); - var msBuildSettings = new DotNetCoreMSBuildSettings + var msBuildSettings = new DotNetMSBuildSettings { - Version = "1.0.0", + Version = string.Format("{0}.{1}.{2}.{3}", + DateTime.Now.Year, + DateTime.Now.Month, + DateTime.Now.Day, + (DateTime.Now.Hour << 4) + DateTime.Now.Minute + ), } .WithProperty("CakeCorePath", typeof(ICakeContext).GetTypeInfo().Assembly.Location) .SetTargetFramework( @@ -18,17 +25,18 @@ Task("Cake.Core.Scripting.AddinDirective.LoadTargetedAddin") { FilePath netCoreApp3_1Path when netCoreApp3_1Path.FullPath.Contains("netcoreapp3.1") => "netcoreapp3.1", FilePath net5_0Path when net5_0Path.FullPath.Contains("net5.0") => "net5.0", - _ => "net6.0" + FilePath net6_0Path when net6_0Path.FullPath.Contains("net6.0") => "net6.0", + _ => "net7.0" } ); - DotNetCorePack($"{Paths.Resources}/Cake.Core/Scripting/addin/addin.csproj", - new DotNetCorePackSettings { + DotNetPack($"{Paths.Resources}/Cake.Core/Scripting/addin/addin.csproj", + new DotNetPackSettings { Configuration = "Release", MSBuildSettings = msBuildSettings }); - var script = $@"#addin nuget:{Paths.Resources}/Cake.Core/Scripting/addin/bin/Release?package=addin&version=1.0.0 + var script = $@"#addin nuget:{Paths.Resources}/Cake.Core/Scripting/addin/bin/Release?package=addin&version={msBuildSettings.Version} Information(""Magic number: {0}"", GetMagicNumber(false)); Information(""The answer to life: {0}"", TheAnswerToLife); Information(""Get Dynamic Magic Number: {0}"", GetDynamicMagicNumber(false).MagicNumber); diff --git a/tests/integration/Cake.Core/Scripting/DefineDirective.cake b/tests/integration/Cake.Core/Scripting/DefineDirective.cake index d504121787..4f1cd7066f 100644 --- a/tests/integration/Cake.Core/Scripting/DefineDirective.cake +++ b/tests/integration/Cake.Core/Scripting/DefineDirective.cake @@ -50,6 +50,8 @@ Task("Cake.Core.Scripting.DefineDirective.Runtime") "5.0", #elif NET6_0 "6.0", +#elif NET7_0 + "7.0", #endif context.Environment.Runtime.BuiltFramework.FullName); }); @@ -66,7 +68,7 @@ Task("Cake.Core.Scripting.DefineDirective.Cake") Assert.True(cake); }); -#if NET5_0 || NET6_0 +#if NET5_0 || NET6_0 || NET7_0 Task("Cake.Core.Scripting.DefineDirective.C#9") .Does(() => { @@ -78,7 +80,7 @@ Task("Cake.Core.Scripting.DefineDirective.Cake") public record CSharpNine(bool IsNine); #endif -#if NET6_0 +#if NET6_0 || NET7_0 Task("Cake.Core.Scripting.DefineDirective.C#10") .Does(() => { @@ -95,14 +97,34 @@ public record CSharpNine(bool IsNine); #endif +#if NET7_0 + Task("Cake.Core.Scripting.DefineDirective.C#11") + .Does(() => +{ + // Given / When / Then + const string longMessage = """ + This is a long message. + It has several lines. + Some are indented + more than others. + Some should start at the first column. + Some have "quoted text" in them. + """; +}); + +#endif + ////////////////////////////////////////////////////////////////////////////// Task("Cake.Core.Scripting.DefineDirective") -#if NET5_0 || NET6_0 +#if NET5_0 || NET6_0 || NET7_0 .IsDependentOn("Cake.Core.Scripting.DefineDirective.C#9") #endif -#if NET6_0 +#if NET6_0 || NET7_0 .IsDependentOn("Cake.Core.Scripting.DefineDirective.C#10") +#endif +#if NET7_0 + .IsDependentOn("Cake.Core.Scripting.DefineDirective.C#11") #endif .IsDependentOn("Cake.Core.Scripting.DefineDirective.Defined") .IsDependentOn("Cake.Core.Scripting.DefineDirective.NotDefined") diff --git a/tests/integration/Cake.Frosting/build/Build.csproj b/tests/integration/Cake.Frosting/build/Build.csproj index 2310bf0411..071df4a56e 100644 --- a/tests/integration/Cake.Frosting/build/Build.csproj +++ b/tests/integration/Cake.Frosting/build/Build.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net5.0;net6.0;net7.0 true