Skip to content

Commit

Permalink
(cake-buildGH-2857) Add support for .NET 5
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Sep 20, 2020
1 parent 19f17e0 commit 3c8a774
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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")
},
Expand Down
2 changes: 1 addition & 1 deletion build.config
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"src"
],
"sdk": {
"version": "3.1.402"
"version": "5.0.100-rc.1.20452.10",
"rollForward": "latestPatch"
}
}
10 changes: 6 additions & 4 deletions src/Cake.Common.Tests/Cake.Common.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Common.Tests</AssemblyName>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
</PropertyGroup>
Expand All @@ -17,12 +17,14 @@
</ItemGroup>
<!-- Global packages -->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<!-- .NET Framework packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
Expand Down
22 changes: 11 additions & 11 deletions src/Cake.Common/Cake.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Common</AssemblyName>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net46;netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -16,15 +16,15 @@
<ItemGroup>
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
</ItemGroup>
<!-- .NET Framework packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Runtime.Serialization.Json" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<!-- .NET Framework packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Runtime.Serialization.Json" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
10 changes: 6 additions & 4 deletions src/Cake.Core.Tests/Cake.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Core.Tests</AssemblyName>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
</PropertyGroup>
Expand All @@ -15,12 +15,14 @@
</ItemGroup>
<!-- Global packages -->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Unit\Scripting\CodeGen\Expected\Methods\*;Unit\Scripting\CodeGen\Expected\Properties\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
Expand Down
17 changes: 17 additions & 0 deletions src/Cake.Core.Tests/Fixtures/NotFormattableFixture.cs
Original file line number Diff line number Diff line change
@@ -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()
{
}
}
}
20 changes: 19 additions & 1 deletion src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -189,7 +190,7 @@ public void Should_Return_Key_If_The_Value_Was_Not_Formattable_With_Different_Pl
// Given
var placeholder = new Tuple<string, string>("{{", "}}");
var transformation = new TextTransformationTemplate("Hello {{pointer:foo}}", placeholder);
transformation.Register("pointer", IntPtr.Zero);
transformation.Register("pointer", NotFormattableFixture.Default);

// When
var result = transformation.Render();
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Core/Cake.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Core</AssemblyName>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net46;netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -13,7 +13,7 @@
<!-- Import shared functionality -->
<Import Project="..\Shared.msbuild" />
<!-- .NET Core packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup Condition=" '$(TargetFramework)' != 'net46' ">
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion src/Cake.Core/Polyfill/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Cake.Core/Scripting/ScriptConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/Cake.NuGet.Tests/Cake.NuGet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.NuGet.Tests</AssemblyName>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
</PropertyGroup>
Expand All @@ -16,12 +16,14 @@
</ItemGroup>
<!-- Global packages -->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<!-- .NET Framework packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
Expand Down
11 changes: 10 additions & 1 deletion src/Cake.NuGet/Cake.NuGet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.NuGet</AssemblyName>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -38,4 +38,13 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.0-rc.1.20451.14" GeneratePathProperty="true">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_Platforms)\runtime.json">
<Link>runtime.json</Link>
</EmbeddedResource>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Cake.Testing.Xunit/Cake.Testing.Xunit.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Testing.Xunit</AssemblyName>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net46;netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Testing.Xunit/RuntimeFact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Testing/Cake.Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Testing</AssemblyName>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net46;netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
10 changes: 6 additions & 4 deletions src/Cake.Tests/Cake.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AssemblyName>Cake.Tests</AssemblyName>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
<LangVersion>latest</LangVersion>
Expand All @@ -12,12 +12,14 @@
<Import Project="..\Shared.msbuild" />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<!-- .NET Framework packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
Expand Down
2 changes: 1 addition & 1 deletion src/Cake/Cake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Cake</AssemblyName>
<OutputType>Exe</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0;net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(PackAsTool)' != 'true'">
Expand Down
2 changes: 1 addition & 1 deletion src/Shared.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<!-- Define .NET Core constants -->
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netcoreapp3.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netcoreapp3.0' OR '$(TargetFramework)' == 'net5.0' ">
<NetStandardImplicitPackageVersion>2.0.0</NetStandardImplicitPackageVersion>
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
<DebugType>portable</DebugType>
Expand Down
Loading

0 comments on commit 3c8a774

Please sign in to comment.