From 3c8a774554fa1c862bbbbae0fa4d464fc9f8b5a0 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Fri, 18 Sep 2020 17:00:38 +0200 Subject: [PATCH] (GH-2857) Add support for .NET 5 --- .travis.yml | 2 +- build.cake | 3 ++- build.config | 2 +- global.json | 3 ++- .../Cake.Common.Tests.csproj | 10 +++++---- src/Cake.Common/Cake.Common.csproj | 22 +++++++++---------- src/Cake.Core.Tests/Cake.Core.Tests.csproj | 10 +++++---- .../Fixtures/NotFormattableFixture.cs | 17 ++++++++++++++ src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs | 20 ++++++++++++++++- .../Text/TextTransformationTemplateTests.cs | 5 +++-- src/Cake.Core/Cake.Core.csproj | 4 ++-- src/Cake.Core/Polyfill/EnvironmentHelper.cs | 10 ++++++++- src/Cake.Core/Scripting/ScriptConventions.cs | 4 ++++ src/Cake.NuGet.Tests/Cake.NuGet.Tests.csproj | 10 +++++---- src/Cake.NuGet/Cake.NuGet.csproj | 11 +++++++++- .../Cake.Testing.Xunit.csproj | 2 +- src/Cake.Testing.Xunit/RuntimeFact.cs | 2 +- src/Cake.Testing/Cake.Testing.csproj | 2 +- src/Cake.Tests/Cake.Tests.csproj | 10 +++++---- src/Cake/Cake.csproj | 2 +- src/Shared.msbuild | 2 +- .../TextTransform/TextTransformAliases.cake | 2 +- .../Cake.Core/Scripting/DefineDirective.cake | 2 ++ 23 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 src/Cake.Core.Tests/Fixtures/NotFormattableFixture.cs diff --git a/.travis.yml b/.travis.yml index cf2345711f..e2f3b0dbd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ mono: - 5.12.0 - 5.20.1 -dotnet: 3.1.402 +dotnet: 5.0.100-rc.1.20452.10 before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags diff --git a/build.cake b/build.cake index 3a0672f296..749d8feab5 100644 --- a/build.cake +++ b/build.cake @@ -151,7 +151,7 @@ Task("Run-Unit-Tests") () => GetFiles("./src/**/*.Tests.csproj"), (parameters, project, context) => { - foreach(var framework in new[] { "netcoreapp2.0", "netcoreapp3.0", "net461" }) + foreach(var framework in new[] { "netcoreapp2.0", "netcoreapp3.0", "net461", "net5.0" }) { FilePath testResultsPath = MakeAbsolute(parameters.Paths.Directories.TestResults .CombineWithFilePath($"{project.GetFilenameWithoutExtension()}_{framework}_TestResults.xml")); @@ -590,6 +590,7 @@ Task("Run-Integration-Tests") parameters => new[] { GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/netcoreapp2.1/**/Cake.dll").Single(), GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/netcoreapp3.0/**/Cake.dll").Single(), + GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net5.0/**/Cake.dll").Single(), parameters.Paths.Directories.IntegrationTestsBinFullFx.CombineWithFilePath("Cake.exe"), parameters.Paths.Directories.IntegrationTestsBinNetCore.CombineWithFilePath("Cake.dll") }, diff --git a/build.config b/build.config index 056724beb9..7c0f69f43a 100644 --- a/build.config +++ b/build.config @@ -1,3 +1,3 @@ #!/usr/bin/env bash CAKE_VERSION=0.38.5 -DOTNET_VERSION=3.1.402 +DOTNET_VERSION=5.0.100-rc.1.20452.10 diff --git a/global.json b/global.json index 54c7256d7f..4168382d94 100644 --- a/global.json +++ b/global.json @@ -3,6 +3,7 @@ "src" ], "sdk": { - "version": "3.1.402" + "version": "5.0.100-rc.1.20452.10", + "rollForward": "latestPatch" } } \ No newline at end of file diff --git a/src/Cake.Common.Tests/Cake.Common.Tests.csproj b/src/Cake.Common.Tests/Cake.Common.Tests.csproj index 71591132e2..ae039b0315 100644 --- a/src/Cake.Common.Tests/Cake.Common.Tests.csproj +++ b/src/Cake.Common.Tests/Cake.Common.Tests.csproj @@ -1,7 +1,7 @@  Cake.Common.Tests - net461;netcoreapp2.1;netcoreapp3.1 + net461;netcoreapp2.1;netcoreapp3.1;net5.0 true true @@ -17,12 +17,14 @@ - + - + + all + runtime; build; native; contentfiles; analyzers + - diff --git a/src/Cake.Common/Cake.Common.csproj b/src/Cake.Common/Cake.Common.csproj index ec080f992e..fe98c55a03 100644 --- a/src/Cake.Common/Cake.Common.csproj +++ b/src/Cake.Common/Cake.Common.csproj @@ -1,7 +1,7 @@  Cake.Common - net46;netstandard2.0 + net46;netstandard2.0;net5.0 Library AnyCpu true @@ -16,15 +16,15 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/src/Cake.Core.Tests/Cake.Core.Tests.csproj b/src/Cake.Core.Tests/Cake.Core.Tests.csproj index f711e4f266..73949f03ad 100644 --- a/src/Cake.Core.Tests/Cake.Core.Tests.csproj +++ b/src/Cake.Core.Tests/Cake.Core.Tests.csproj @@ -1,7 +1,7 @@  Cake.Core.Tests - net461;netcoreapp2.1;netcoreapp3.1 + net461;netcoreapp2.1;netcoreapp3.1;net5.0 true true @@ -15,12 +15,14 @@ - + - + + all + runtime; build; native; contentfiles; analyzers + - diff --git a/src/Cake.Core.Tests/Fixtures/NotFormattableFixture.cs b/src/Cake.Core.Tests/Fixtures/NotFormattableFixture.cs new file mode 100644 index 0000000000..1f1e0bdade --- /dev/null +++ b/src/Cake.Core.Tests/Fixtures/NotFormattableFixture.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cake.Core.Tests.Fixtures +{ + internal sealed class NotFormattableFixture + { + public static NotFormattableFixture Default { get; } = new NotFormattableFixture(); + + private NotFormattableFixture() + { + } + } +} diff --git a/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs b/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs index 28beda0545..539ed3b802 100644 --- a/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs +++ b/src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs @@ -40,7 +40,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 NETCOREAPP2_0 +#if NET5_0 + "5.0"); +#elif NETCOREAPP2_0 "2.0"); #elif NETCOREAPP2_1 "2.1"); @@ -61,6 +63,7 @@ public void Should_Return_Correct_Result_For_CoreClr() case ".NETCoreApp,Version=v2.1": case ".NETCoreApp,Version=v3.0": case ".NETCoreApp,Version=v3.1": + case ".NETCoreApp,Version=v5.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -75,6 +78,7 @@ public void Should_Return_Correct_Result_For_CoreClr() { case ".NETCoreApp,Version=v3.0": case ".NETCoreApp,Version=v3.1": + case ".NETCoreApp,Version=v5.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -88,6 +92,7 @@ public void Should_Return_Correct_Result_For_CoreClr() switch (framework.FullName) { case ".NETCoreApp,Version=v3.1": + case ".NETCoreApp,Version=v5.0": { TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); expect = framework.FullName; @@ -96,6 +101,19 @@ public void Should_Return_Correct_Result_For_CoreClr() } break; } + case ".NETCoreApp,Version=v3.1": + { + switch (framework.FullName) + { + case ".NETCoreApp,Version=v5.0": + { + TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName); + expect = framework.FullName; + break; + } + } + break; + } } Assert.Equal(expect, framework.FullName); #endif diff --git a/src/Cake.Core.Tests/Unit/Text/TextTransformationTemplateTests.cs b/src/Cake.Core.Tests/Unit/Text/TextTransformationTemplateTests.cs index c4f13ab9ac..a92fdc6982 100644 --- a/src/Cake.Core.Tests/Unit/Text/TextTransformationTemplateTests.cs +++ b/src/Cake.Core.Tests/Unit/Text/TextTransformationTemplateTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using Cake.Core.Tests.Fixtures; using Cake.Core.Text; using Xunit; @@ -174,7 +175,7 @@ public void Should_Return_Key_If_The_Value_Was_Not_Formattable() { // Given var transformation = new TextTransformationTemplate("Hello <%pointer:foo%>"); - transformation.Register("pointer", IntPtr.Zero); + transformation.Register("pointer", NotFormattableFixture.Default); // When var result = transformation.Render(); @@ -189,7 +190,7 @@ public void Should_Return_Key_If_The_Value_Was_Not_Formattable_With_Different_Pl // Given var placeholder = new Tuple("{{", "}}"); var transformation = new TextTransformationTemplate("Hello {{pointer:foo}}", placeholder); - transformation.Register("pointer", IntPtr.Zero); + transformation.Register("pointer", NotFormattableFixture.Default); // When var result = transformation.Render(); diff --git a/src/Cake.Core/Cake.Core.csproj b/src/Cake.Core/Cake.Core.csproj index b7066fded6..a03f69971a 100644 --- a/src/Cake.Core/Cake.Core.csproj +++ b/src/Cake.Core/Cake.Core.csproj @@ -1,7 +1,7 @@  Cake.Core - net46;netstandard2.0 + net46;netstandard2.0;net5.0 Library AnyCpu true @@ -13,7 +13,7 @@ - + diff --git a/src/Cake.Core/Polyfill/EnvironmentHelper.cs b/src/Cake.Core/Polyfill/EnvironmentHelper.cs index 458c22909d..d21574b019 100644 --- a/src/Cake.Core/Polyfill/EnvironmentHelper.cs +++ b/src/Cake.Core/Polyfill/EnvironmentHelper.cs @@ -139,7 +139,15 @@ public static FrameworkName GetBuiltFramework() return netCoreAppFramwork; } - var assemblyPath = typeof(System.Runtime.GCSettings)?.GetTypeInfo()?.Assembly?.CodeBase; + var assemblyPath = typeof(System.Runtime.GCSettings)?.GetTypeInfo() + ?.Assembly +#if NET5_0 + ?.Location; +#else +#pragma warning disable 0618 + ?.CodeBase; +#pragma warning restore 0618 +#endif if (string.IsNullOrEmpty(assemblyPath)) { return NetStandardFramework; diff --git a/src/Cake.Core/Scripting/ScriptConventions.cs b/src/Cake.Core/Scripting/ScriptConventions.cs index 5260bcefe1..b3d8a0d8d0 100644 --- a/src/Cake.Core/Scripting/ScriptConventions.cs +++ b/src/Cake.Core/Scripting/ScriptConventions.cs @@ -146,7 +146,11 @@ private string GetFrameworkDefine() case ".NETCoreApp,Version=v3.1": return "NETCOREAPP3_1"; + case ".NETCoreApp,Version=v5.0": + return "NET5_0"; + default: + Console.Error.WriteLine(_runtime.BuiltFramework.FullName); return "NETSTANDARD2_0"; } } diff --git a/src/Cake.NuGet.Tests/Cake.NuGet.Tests.csproj b/src/Cake.NuGet.Tests/Cake.NuGet.Tests.csproj index c555f810f4..32db410cc5 100644 --- a/src/Cake.NuGet.Tests/Cake.NuGet.Tests.csproj +++ b/src/Cake.NuGet.Tests/Cake.NuGet.Tests.csproj @@ -1,7 +1,7 @@  Cake.NuGet.Tests - net461;netcoreapp2.1;netcoreapp3.1 + net461;netcoreapp2.1;netcoreapp3.1;net5.0 true true @@ -16,12 +16,14 @@ - + - + + all + runtime; build; native; contentfiles; analyzers + - diff --git a/src/Cake.NuGet/Cake.NuGet.csproj b/src/Cake.NuGet/Cake.NuGet.csproj index 322402d61c..acc5d6d232 100644 --- a/src/Cake.NuGet/Cake.NuGet.csproj +++ b/src/Cake.NuGet/Cake.NuGet.csproj @@ -1,7 +1,7 @@  Cake.NuGet - net461;netstandard2.0 + net461;netstandard2.0;net5.0 Library AnyCpu true @@ -38,4 +38,13 @@ + + + All + + + runtime.json + + + \ No newline at end of file diff --git a/src/Cake.Testing.Xunit/Cake.Testing.Xunit.csproj b/src/Cake.Testing.Xunit/Cake.Testing.Xunit.csproj index afcf91b89b..16f44d79f7 100644 --- a/src/Cake.Testing.Xunit/Cake.Testing.Xunit.csproj +++ b/src/Cake.Testing.Xunit/Cake.Testing.Xunit.csproj @@ -1,7 +1,7 @@  Cake.Testing.Xunit - net46;netstandard2.0 + net46;netstandard2.0;net5.0 Library AnyCpu true diff --git a/src/Cake.Testing.Xunit/RuntimeFact.cs b/src/Cake.Testing.Xunit/RuntimeFact.cs index 7de3a549b4..17b0502d9e 100644 --- a/src/Cake.Testing.Xunit/RuntimeFact.cs +++ b/src/Cake.Testing.Xunit/RuntimeFact.cs @@ -19,7 +19,7 @@ public RuntimeFact(TestRuntime runtime) else if (runtime.HasFlag(TestRuntime.CoreClr) && EnvironmentHelper.GetRuntime() != Runtime.CoreClr) { - Skip = ".NET Core 2 test."; + Skip = ".NET Core test."; } } } diff --git a/src/Cake.Testing/Cake.Testing.csproj b/src/Cake.Testing/Cake.Testing.csproj index e485cd8cc7..a4adabec46 100644 --- a/src/Cake.Testing/Cake.Testing.csproj +++ b/src/Cake.Testing/Cake.Testing.csproj @@ -1,7 +1,7 @@  Cake.Testing - net46;netstandard2.0 + net46;netstandard2.0;net5.0 Library AnyCpu true diff --git a/src/Cake.Tests/Cake.Tests.csproj b/src/Cake.Tests/Cake.Tests.csproj index 67d6ea0f05..56f6a1158e 100644 --- a/src/Cake.Tests/Cake.Tests.csproj +++ b/src/Cake.Tests/Cake.Tests.csproj @@ -2,7 +2,7 @@ Cake.Tests - net461;netcoreapp2.1;netcoreapp3.1 + net461;netcoreapp2.1;netcoreapp3.1;net5.0 true true latest @@ -12,12 +12,14 @@ - + - + + all + runtime; build; native; contentfiles; analyzers + - diff --git a/src/Cake/Cake.csproj b/src/Cake/Cake.csproj index 220b9734ac..34ffdc4950 100644 --- a/src/Cake/Cake.csproj +++ b/src/Cake/Cake.csproj @@ -4,7 +4,7 @@ Cake Exe AnyCpu - netcoreapp2.1;netcoreapp3.0 + netcoreapp2.1;netcoreapp3.0;net5.0 diff --git a/src/Shared.msbuild b/src/Shared.msbuild index 6eff2d0697..26290124da 100644 --- a/src/Shared.msbuild +++ b/src/Shared.msbuild @@ -14,7 +14,7 @@ - + 2.0.0 $(DefineConstants);NETCORE portable diff --git a/tests/integration/Cake.Common/Tools/TextTransform/TextTransformAliases.cake b/tests/integration/Cake.Common/Tools/TextTransform/TextTransformAliases.cake index ad00262203..fd90ca9f8f 100644 --- a/tests/integration/Cake.Common/Tools/TextTransform/TextTransformAliases.cake +++ b/tests/integration/Cake.Common/Tools/TextTransform/TextTransformAliases.cake @@ -7,7 +7,7 @@ Task("Cake.Common.Tools.TextTransform.TextTransformAliases.TransformTemplate.Set var t4Path = Context.Tools.Resolve("t4") ?? Context.Tools.Resolve("t4.exe"); if (t4Path == null) { - DotNetCoreTool(null, "tool", "install --tool-path ./tools dotnet-t4 --version 2.0.5"); + DotNetCoreTool(null, "tool", "install --tool-path ./tools dotnet-t4 --version \"2.2.0-preview-0020-g990c44075e\" --add-source \"https://pkgs.dev.azure.com/cake-build/Cake/_packaging/cake/nuget/v3/index.json\""); } }); diff --git a/tests/integration/Cake.Core/Scripting/DefineDirective.cake b/tests/integration/Cake.Core/Scripting/DefineDirective.cake index da27f6f35c..bd4bd9df5b 100644 --- a/tests/integration/Cake.Core/Scripting/DefineDirective.cake +++ b/tests/integration/Cake.Core/Scripting/DefineDirective.cake @@ -46,6 +46,8 @@ Task("Cake.Core.Scripting.DefineDirective.Runtime") "3.0", #elif NETCOREAPP3_1 "3.1", +#elif NET5_0 + "5.0", #endif context.Environment.Runtime.BuiltFramework.FullName); });