Skip to content

Commit

Permalink
Merge pull request cake-build#3990 from devlead/feature/cake-buildgh-…
Browse files Browse the repository at this point in the history
…3950

GH3950: Add .NET 7 Support
devlead authored Oct 17, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents c77fd70 + 1efd351 commit bffc607
Showing 13 changed files with 89 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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:
5 changes: 3 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
@@ -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) =>
{
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"src"
],
"sdk": {
"version": "6.0.402",
"version": "7.0.100-rc.2.22477.23",
"rollForward": "latestFeature"
}
}
22 changes: 21 additions & 1 deletion src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions src/Cake.Core/Scripting/ScriptConventions.cs
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion src/Cake.NuGet/Cake.NuGet.csproj
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Platforms" Version="6.0.6" GeneratePathProperty="true">
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.0-rc.2.22472.3" GeneratePathProperty="true">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_Platforms)\runtime.json">
7 changes: 4 additions & 3 deletions src/Cake/Cake.csproj
Original file line number Diff line number Diff line change
@@ -26,10 +26,11 @@

<!-- Global packages -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.3.1" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="6.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.4.0-2.final" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0-rc.2.22472.3" />
<PackageReference Include="System.Reflection.Metadata" Version="7.0.0-rc.2.22472.3 " />
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.3.0" Condition="'$(TargetFramework)' == 'net7.0'" />
<PackageReference Include="Basic.Reference.Assemblies.Net60" Version="1.3.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Basic.Reference.Assemblies.Net50" Version="1.3.0" Condition="'$(TargetFramework)' == 'net5.0'" />
<PackageReference Include="Basic.Reference.Assemblies.NetCoreApp31" Version="1.3.0" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
Original file line number Diff line number Diff line change
@@ -26,8 +26,10 @@ IEnumerable<Assembly> 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;
6 changes: 3 additions & 3 deletions src/Shared.msbuild
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- General package metadata -->
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<PackageId>$(AssemblyName)</PackageId>
<Copyright>Copyright (c) .NET Foundation and contributors</Copyright>
<Authors>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</Authors>
@@ -12,12 +12,12 @@
<RepositoryType>git</RepositoryType>
<PackageTags>Cake;Script;Build</PackageTags>
<PackageProjectUrl>https://cakebuild.net</PackageProjectUrl>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<PackageReadmeFile>NuGet.org.md</PackageReadmeFile>
</PropertyGroup>

<!-- Define .NET Core constants -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0' ">
<NetStandardImplicitPackageVersion>2.0.0</NetStandardImplicitPackageVersion>
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
<DebugType>portable</DebugType>
Original file line number Diff line number Diff line change
@@ -16,14 +16,16 @@ 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))
);

Task("ValidatePath")
.DoesForEach<BuildData, string>(
new [] {
"Cake\\WTool\\Wtools\\Wnet7\\W0",
"Cake\\WTool\\Wtools\\Wnet6\\W0",
"Cake\\WTool\\Wtools\\Wnet5\\W0",
"Cake\\WTool\\Wtools\\Wnetcoreapp3\\W1"
22 changes: 15 additions & 7 deletions tests/integration/Cake.Core/Scripting/AddinDirective.cake
Original file line number Diff line number Diff line change
@@ -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,27 +10,33 @@ 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(
cake switch
{
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);
30 changes: 26 additions & 4 deletions tests/integration/Cake.Core/Scripting/DefineDirective.cake
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion tests/integration/Cake.Frosting/build/Build.csproj
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>

<!-- Make sure start same folder .NET Core CLI and Visual Studio -->

0 comments on commit bffc607

Please sign in to comment.