Skip to content

Commit

Permalink
Merge pull request #2858 from devlead/feature/gh-2857
Browse files Browse the repository at this point in the history
GH2857: Add support for .NET 5
  • Loading branch information
patriksvensson authored Sep 25, 2020
2 parents d53f051 + f887590 commit 7a978a0
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 59 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
Expand All @@ -20,11 +21,21 @@ jobs:
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow

- name: Install .NET Core SDK 2.1.810
uses: actions/setup-dotnet@v1
with:
dotnet-version: '2.1.810'

- name: Install .NET Core SDK 3.1.402
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.402'

- name: Install .NET Core SDK 5.0.100-rc.1.20452.10
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.100-rc.1.20452.10'

- name: Run Cake script
uses: ecampidoglio/[email protected]
env:
Expand Down
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
9 changes: 6 additions & 3 deletions 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 @@ -208,6 +208,7 @@ Task("Validate-Version")
var fullFxExe = MakeAbsolute(parameters.Paths.Directories.ArtifactsBinFullFx.CombineWithFilePath("Cake.exe"));
var coreFxExe = MakeAbsolute(parameters.Paths.Directories.ArtifactsBinNetCore.CombineWithFilePath("Cake.dll"));
context.Information("Testing {0} version...", fullFxExe);
IEnumerable<string> fullFxOutput;
var fullFxResult = StartProcess(
fullFxExe,
Expand All @@ -220,9 +221,10 @@ Task("Validate-Version")
);
var fullFxVersion = string.Concat(fullFxOutput);
context.Information("Testing {0} version...", coreFxExe);
IEnumerable<string> coreFxOutput;
var coreFxResult = StartProcess(
"dotnet",
context.Tools.Resolve("dotnet") ?? context.Tools.Resolve("dotnet.exe"),
new ProcessSettings {
Arguments = $"\"{coreFxExe}\" --version",
RedirectStandardOutput = true,
Expand Down Expand Up @@ -590,6 +592,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 Expand Up @@ -617,7 +620,7 @@ Task("Run-Integration-Tests")
catch(Exception ex)
{
Error("While testing: {0}\r\n{1}", cakeAssembly, ex);
throw;
throw new Exception($"Exception while testing: {cakeAssembly}", ex);
}
finally
{
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"
}
}
12 changes: 7 additions & 5 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-20200921-01" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.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.2" />
<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>
12 changes: 7 additions & 5 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-20200921-01" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.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.2" />
<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
6 changes: 6 additions & 0 deletions src/Cake.Core.Tests/Fixtures/NotFormattableFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Cake.Core.Tests.Fixtures
{
internal sealed class 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 @@ -173,8 +174,9 @@ public void Should_Trim_Content_Of_Token(string template)
public void Should_Return_Key_If_The_Value_Was_Not_Formattable()
{
// Given
var notFormattable = new NotFormattableFixture();
var transformation = new TextTransformationTemplate("Hello <%pointer:foo%>");
transformation.Register("pointer", IntPtr.Zero);
transformation.Register("pointer", notFormattable);

// When
var result = transformation.Render();
Expand All @@ -187,9 +189,10 @@ public void Should_Return_Key_If_The_Value_Was_Not_Formattable()
public void Should_Return_Key_If_The_Value_Was_Not_Formattable_With_Different_Placeholder()
{
// Given
var notFormattable = new NotFormattableFixture();
var placeholder = new Tuple<string, string>("{{", "}}");
var transformation = new TextTransformationTemplate("Hello {{pointer:foo}}", placeholder);
transformation.Register("pointer", IntPtr.Zero);
transformation.Register("pointer", notFormattable);

// 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
12 changes: 7 additions & 5 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-20200921-01" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.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.2" />
<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
Loading

0 comments on commit 7a978a0

Please sign in to comment.