Skip to content

Commit

Permalink
(cake-buildGH-4345) Add .NET 9 (net9.0) TFM
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Oct 28, 2024
1 parent 3df1b94 commit 9ddf75c
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 44 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ jobs:
os: [windows-latest, macos-13, ubuntu-latest]
steps:
- name: Get the sources
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install .NET SDK 6.0.x - 8.0.x
uses: actions/setup-dotnet@v3
- name: Install .NET SDK 8.0.x - 9.0.x
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Install .NET Core SDK (global.json)
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

Expand All @@ -47,7 +46,6 @@ jobs:
script-path: tests/integration/Cake.Common/Build/GitHubActions/ValidateGitHubActionsProvider.cake
cake-version: tool-manifest
arguments: |
CAKE_NETCOREAPP_6_0_VERSION_OS: ${{ steps.build-cake.outputs.CAKE_NETCOREAPP_6_0_VERSION_OS }}
CAKE_NETCOREAPP_7_0_VERSION_OS: ${{ steps.build-cake.outputs.CAKE_NETCOREAPP_7_0_VERSION_OS }}
CAKE_NETCOREAPP_8_0_VERSION_OS: ${{ steps.build-cake.outputs.CAKE_NETCOREAPP_8_0_VERSION_OS }}
CAKE_NETCOREAPP_9_0_VERSION_OS: ${{ steps.build-cake.outputs.CAKE_NETCOREAPP_9_0_VERSION_OS }}
ValidateGitHubActionsProvider: true
5 changes: 3 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Task("Run-Unit-Tests")
() => GetFiles("./src/**/*.Tests.csproj"),
(parameters, project, context) =>
{
foreach(var framework in new[] { "net8.0" })
foreach(var framework in new[] { "net8.0", "net9.0" })
{
FilePath testResultsPath = MakeAbsolute(parameters.Paths.Directories.TestResults
.CombineWithFilePath($"{project.GetFilenameWithoutExtension()}_{framework}_TestResults.xml"));
Expand Down Expand Up @@ -368,7 +368,8 @@ Task("Run-Integration-Tests")
.DeferOnError()
.DoesForEach<BuildParameters, FilePath>(
parameters => new[] {
GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net8.0/**/Cake.dll").Single()
GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net8.0/**/Cake.dll").Single(),
GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/net9.0/**/Cake.dll").Single()
},
(parameters, cakeAssembly, context) =>
{
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"src"
],
"sdk": {
"version": "8.0.403",
"version": "9.0.100-rc.2.24474.11",
"rollForward": "latestFeature"
}
}
10 changes: 9 additions & 1 deletion src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 NET8_0
#if NET9_0
"9.0");
#elif NET8_0
"8.0");
#elif NET7_0
"7.0");
Expand Down Expand Up @@ -71,6 +73,7 @@ public void Should_Return_Correct_Result_For_CoreClr()
case ".NETCoreApp,Version=v5.0":
case ".NETCoreApp,Version=v6.0":
case ".NETCoreApp,Version=v7.0":
case ".NETCoreApp,Version=v8.0":
{
TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName);
expect = framework.FullName;
Expand All @@ -88,6 +91,7 @@ public void Should_Return_Correct_Result_For_CoreClr()
case ".NETCoreApp,Version=v5.0":
case ".NETCoreApp,Version=v6.0":
case ".NETCoreApp,Version=v7.0":
case ".NETCoreApp,Version=v8.0":
{
TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName);
expect = framework.FullName;
Expand All @@ -104,6 +108,7 @@ public void Should_Return_Correct_Result_For_CoreClr()
case ".NETCoreApp,Version=v5.0":
case ".NETCoreApp,Version=v6.0":
case ".NETCoreApp,Version=v7.0":
case ".NETCoreApp,Version=v8.0":
{
TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName);
expect = framework.FullName;
Expand All @@ -119,6 +124,7 @@ public void Should_Return_Correct_Result_For_CoreClr()
case ".NETCoreApp,Version=v5.0":
case ".NETCoreApp,Version=v6.0":
case ".NETCoreApp,Version=v7.0":
case ".NETCoreApp,Version=v8.0":
{
TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName);
expect = framework.FullName;
Expand All @@ -133,6 +139,7 @@ public void Should_Return_Correct_Result_For_CoreClr()
{
case ".NETCoreApp,Version=v6.0":
case ".NETCoreApp,Version=v7.0":
case ".NETCoreApp,Version=v8.0":
{
TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName);
expect = framework.FullName;
Expand All @@ -146,6 +153,7 @@ public void Should_Return_Correct_Result_For_CoreClr()
switch (framework.FullName)
{
case ".NETCoreApp,Version=v7.0":
case ".NETCoreApp,Version=v8.0":
{
TestOutputHelper.WriteLine("Expect changed from {0} to {1}.", expect, framework.FullName);
expect = framework.FullName;
Expand Down
3 changes: 3 additions & 0 deletions src/Cake.Core/Scripting/ScriptConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ private string GetFrameworkDefine()
case ".NETCoreApp,Version=v8.0":
return "NET8_0";

case ".NETCoreApp,Version=v9.0":
return "NET9_0";

default:
Console.Error.WriteLine(_runtime.BuiltFramework.FullName);
Console.Error.Flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
"type": "parameter",
"description": "The target framework for the project.",
"datatype": "choice",
"defaultValue": "net8.0",
"defaultValue": "net9.0",
"replaces": "TargetFrameworkValue",
"choices": [
{
"choice": "net8.0",
"description": "Target .NET 8"
},
{
"choice": "net9.0",
"description": "Target .NET 9"
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions src/Cake.NuGet/Cake.NuGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<PackageReference Include="NuGet.Resolver" />
<PackageReference Include="NuGet.Common" />
<PackageReference Include="Newtonsoft.Json" />

<!-- Pin nuget transitive packages vulnerability issues NuGet.Packaging -->
<PackageReference Include="System.Security.Cryptography.Pkcs" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Cake/Cake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<PackageReference Include="System.Reflection.Metadata" />
<PackageReference Include="Autofac" />
<PackageReference Include="Basic.Reference.Assemblies.Net80" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Basic.Reference.Assemblies.Net90" Condition="'$(TargetFramework)' == 'net9.0'" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ IEnumerable<Assembly> TryGetReferenceAssemblies()
foreach (var reference in
#if NET8_0
Basic.Reference.Assemblies.Net80.References.All)
#else
Basic.Reference.Assemblies.Net90.References.All)
#endif
{
Assembly assembly;
Expand Down
5 changes: 5 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageVersion Include="Autofac" Version="8.1.1" />
<PackageVersion Include="Basic.Reference.Assemblies.Net80" Version="1.7.9" />
<PackageVersion Include="Basic.Reference.Assemblies.Net90" Version="1.7.9" />
<PackageVersion Include="Cake.Frosting" Version="3.1.0.0" />
<PackageVersion Include="Castle.Core" Version="5.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
Expand All @@ -34,5 +35,9 @@
<PackageVersion Include="Verify.Xunit" Version="27.0.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />

<!-- Pin nuget transitive packages vulnerability issues NuGet.Packaging -->
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="9.0.0-rc.2.24473.5" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Shared.msbuild
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- General package metadata -->
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Setup(
Task("ValidateEnvironment")
.DoesForEach<BuildData, string>(
data => new [] {
$"CAKE_{data.OS}_NETCOREAPP_8_0_VERSION"
$"CAKE_{data.OS}_NETCOREAPP_8_0_VERSION",
$"CAKE_{data.OS}_NETCOREAPP_9_0_VERSION"
},
(data, envKey) => Assert.Equal(data.GitVersion, EnvironmentVariable(envKey))
);
Expand All @@ -29,14 +30,16 @@ Task("ValidatePath")
.DoesForEach<BuildData, string>(
new [] {
"Cake\\WTool\\Wtools\\Wnet8\\W0",
"Cake\\WTool\\Wtools\\Wnet9\\W0"
},
(data, path) => Assert.Matches(path, data.Path)
);

Task("ValidateVariable")
.DoesForEach<BuildData, string>(
() => new [] {
"CAKE_NETCOREAPP_8_0_VERSION_OS"
"CAKE_NETCOREAPP_8_0_VERSION_OS",
"CAKE_NETCOREAPP_9_0_VERSION_OS"
},
(data, varKey) => Assert.Equal(data.GitVersionAndOS, Argument<string>(varKey))
);
Expand Down
18 changes: 3 additions & 15 deletions tests/integration/Cake.Common/Tools/Command/CommandAliases.cake
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ Usage:
Arguments:
<PACKAGE_ID> The NuGet Package Id of the tool to list
Options:
-g, --global List tools installed for the current user.
--local List the tools installed in the local tool manifest.
--tool-path <PATH> The directory containing the tools to list.
-?, -h, --help Show command line help.";
Options:";

// When
var exitCode = ctx.Command(settings.ToolExecutableNames, out var standardOutput, "tool list -h");
Expand All @@ -65,11 +61,7 @@ Usage:
Arguments:
<PACKAGE_ID> The NuGet Package Id of the tool to list
Options:
-g, --global List tools installed for the current user.
--local List the tools installed in the local tool manifest.
--tool-path <PATH> The directory containing the tools to list.
-?, -h, --help Show command line help.";
Options:";

// When
var exitCode = ctx.Command(settings, out var standardOutput, "tool list -h");
Expand All @@ -94,11 +86,7 @@ Usage:
Arguments:
<PACKAGE_ID> The NuGet Package Id of the tool to list
Options:
-g, --global List tools installed for the current user.
--local List the tools installed in the local tool manifest.
--tool-path <PATH> The directory containing the tools to list.
-?, -h, --help Show command line help.";
Options:";

// When
var exitCode = ctx.Command(
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/Cake.Common/Tools/DotNet/DotNetAliases.cake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuild")
// Given
var path = Paths.Temp.Combine("./Cake.Common/Tools/DotNet");
var project = path.CombineWithFilePath("hwapp/hwapp.csproj");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net8.0/hwapp.dll");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net9.0/hwapp.dll");

// When
DotNetBuild(project.FullPath);
Expand All @@ -61,7 +61,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetVSTest")
{
// Given
var path = Paths.Temp.Combine("./Cake.Common/Tools/DotNet");
var assembly = path.CombineWithFilePath("hwapp.tests/bin/Debug/net8.0/hwapp.tests.dll");
var assembly = path.CombineWithFilePath("hwapp.tests/bin/Debug/net9.0/hwapp.tests.dll");

// When
DotNetVSTest(assembly.FullPath);
Expand Down Expand Up @@ -184,7 +184,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetExecute")
{
// Given
var path = Paths.Temp.Combine("./Cake.Common/Tools/DotNet");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net8.0/hwapp.dll");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net9.0/hwapp.dll");

// When
DotNetExecute(assembly);
Expand All @@ -197,7 +197,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetClean")
// Given
var path = Paths.Temp.Combine("./Cake.Common/Tools/DotNet");
var project = path.CombineWithFilePath("hwapp/hwapp.csproj");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net8.0/hwapp.dll");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net9.0/hwapp.dll");
Assert.True(System.IO.File.Exists(assembly.FullPath));

// When
Expand All @@ -214,7 +214,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetMSBuild")
// Given
var path = Paths.Temp.Combine("./Cake.Common/Tools/DotNet");
var project = path.CombineWithFilePath("hwapp/hwapp.csproj");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net8.0/hwapp.dll");
var assembly = path.CombineWithFilePath("hwapp/bin/Debug/net9.0/hwapp.dll");

// When
DotNetMSBuild(project.FullPath);
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/Cake.Core/Scripting/AddinDirective.cake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Task("Cake.Core.Scripting.AddinDirective.LoadTargetedAddin")
.SetTargetFramework(
cake switch
{
_ => "net8.0"
FilePath net8_0Path when net8_0Path.FullPath.Contains("net8.0") => "net8.0",
_ => "net9.0"
}
);

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/Cake.Core/Scripting/DefineDirective.cake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Task("Cake.Core.Scripting.DefineDirective.Runtime")
"7.0",
#elif NET8_0
"8.0",
#elif NET9_0
"9.0",
#endif
context.Environment.Runtime.BuiltFramework.FullName);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Cake.Frosting/build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>

<!-- Make sure start same folder .NET Core CLI and Visual Studio -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\hwapp.common\hwapp.common.csproj" />
Expand Down

0 comments on commit 9ddf75c

Please sign in to comment.