Skip to content

Commit

Permalink
(cake-contribGH-389) Multi-Target .NET8
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Dec 9, 2023
1 parent c9d7eaa commit fe532fe
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Cake.Frosting.Issues.Recipe.xml</DocumentationFile>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
Expand Down
42 changes: 40 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ jobs:
- task: UseDotNet@2
inputs:
version: '5.x'
displayName: 'Install .NET 5'
- task: UseDotNet@2
inputs:
version: '6.x'
displayName: 'Install .NET 6'
- task: UseDotNet@2
inputs:
version: '7.x'
- powershell: ./build.ps1
displayName: 'Build'
displayName: 'Install .NET 7'
- task: UseDotNet@2
inputs:
version: '8.x'
displayName: 'Install .NET 8'
- publish: $(Build.SourcesDirectory)/BuildArtifacts/Packages/NuGet
artifact: NuGet Package
displayName: 'Publish NuGet package as build artifact'
Expand All @@ -40,6 +45,7 @@ jobs:
- task: UseDotNet@2
inputs:
version: '6.x'
displayName: 'Install .NET 6'
- task: NodeTool@0
inputs:
versionSpec: '14.x'
Expand Down Expand Up @@ -70,6 +76,7 @@ jobs:
- task: UseDotNet@2
inputs:
version: '7.x'
displayName: 'Install .NET 7'
- task: NodeTool@0
inputs:
versionSpec: '14.x'
Expand All @@ -90,6 +97,37 @@ jobs:
- publish: $(Build.SourcesDirectory)/tests/frosting/net7.0/build/BuildArtifacts/output
artifact: Integration Tests Frosting Windows 2022 (.NET 7)
displayName: 'Publish generated reports as build artifact'
# Integration Tests Frosting Windows (.NET 8)
- job: Test_Frosting_Windows_2022_Net8
displayName: Integration Tests Frosting Windows 2022 (.NET 8)
dependsOn: Build
pool:
vmImage: 'windows-2022'
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
displayName: 'Install .NET 8'
- task: NodeTool@0
inputs:
versionSpec: '14.x'
displayName: 'Install NodeJs 14.x'
- powershell: choco install markdownlint-cli --no-progress
displayName: 'Install required tools'
- download: current
artifact: NuGet Package
displayName: 'Download build artifact'
- task: CopyFiles@2
inputs:
sourceFolder: $(Pipeline.Workspace)/NuGet Package
targetFolder: $(Build.SourcesDirectory)/BuildArtifacts/Packages/NuGet
displayName: 'Copy build artifact for test run'
- powershell: ./build.ps1 --verbosity=diagnostic
workingDirectory: ./tests/frosting/net8.0
displayName: 'Run integration tests'
- publish: $(Build.SourcesDirectory)/tests/frosting/net8.0/build/BuildArtifacts/output
artifact: Integration Tests Frosting Windows 2022 (.NET 8)
displayName: 'Publish generated reports as build artifact'
# Integration Tests Script Runner Windows 2019 (.NET Core tool)
- job: Test_Script_Runner_Windows_2019_DotNetCoreTool
displayName: Integration Tests Script Runner Windows 2019 (.NET Core tool)
Expand Down
13 changes: 13 additions & 0 deletions tests/frosting/net8.0/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$RECIPE_PACKAGE_PATH = "packages/cake.frosting.issues.recipe"
if (Test-Path $RECIPE_PACKAGE_PATH)
{
Write-Host "Cleaning up cached version of $RECIPE_PACKAGE_PATH..."
Remove-Item $RECIPE_PACKAGE_PATH -Recurse;
}
else
{
Write-Host "$RECIPE_PACKAGE_PATH not cached..."
}

dotnet run --project build/Build.csproj -- $args
exit $LASTEXITCODE;
11 changes: 11 additions & 0 deletions tests/frosting/net8.0/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

$RECIPE_PACKAGE_PATH = "packages/cake.frosting.issues.recipe"
if [ -d "$RECIPE_PACKAGE_PATH" ]
then
echo "Cleaning up cached version of $RECIPE_PACKAGE_PATH..."
rm -Rf $RECIPE_PACKAGE_PATH
else
echo "$RECIPE_PACKAGE_PATH not cached..."
fi

dotnet run --project ./build/Build.csproj -- "$@"
2 changes: 2 additions & 0 deletions tests/frosting/net8.0/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Cake ###
tools/*
11 changes: 11 additions & 0 deletions tests/frosting/net8.0/build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="3.0.0" />
<PackageReference Include="Cake.Frosting.Issues.Recipe" Version="*-*" />
</ItemGroup>
</Project>
125 changes: 125 additions & 0 deletions tests/frosting/net8.0/build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using System.Reflection;
using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Common.Tools.InspectCode;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Frosting;
using Cake.Frosting.Issues.Recipe;

public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.UseLifetime<Lifetime>()
.InstallTool(new Uri("nuget:?package=JetBrains.ReSharper.CommandLineTools"))
// Register Cake.Frosting.Issues.Recipe tasks.
.AddAssembly(Assembly.GetAssembly(typeof(IssuesTask)))
.Run(args);
}
}

public class BuildContext : IssuesContext<BuildParameters, BuildState>
{
public BuildContext(ICakeContext context)
: base(context)
{
}

protected override BuildParameters CreateIssuesParameters()
{
return new BuildParameters();
}

protected override BuildState CreateIssuesState()
{
return new BuildState(this);
}
}

public class BuildParameters : IssuesParameters
{
public DirectoryPath LogDirectoryPath => this.OutputDirectory.Combine("logs");

public BuildParameters()
{
this.OutputDirectory = this.OutputDirectory.Combine("output");
}
}

public class BuildState : IssuesState
{
public FilePath SolutionFilePath { get; }

public BuildState(BuildContext context)
: base(context, RepositoryInfoProviderType.Cli)
{
this.SolutionFilePath =
this.ProjectRootDirectory
.Combine("src")
.CombineWithFilePath("ClassLibrary1.sln");
}
}

public class Lifetime : FrostingLifetime<BuildContext>
{
public override void Setup(BuildContext context, ISetupContext info)
{
// Determine Build Identifier
var platform = context.Environment.Platform.Family.ToString();
var runtime = context.Environment.Runtime.IsCoreClr ? ".NET Core" : ".NET Framework";

context.Parameters.BuildIdentifier = $"Cake Frosting {platform} ({runtime})";

context.Information("Build identifier: {0}", context.Parameters.BuildIdentifier);
}

public override void Teardown(BuildContext context, ITeardownContext info)
{
}
}

[TaskName("Run-InspectCode")]
public sealed class RunInspectCodeTask : FrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
return context.IsRunningOnWindows();
}

public override void Run(BuildContext context)
{
// Run InspectCode.
var inspectCodeLogFilePath = context.Parameters.LogDirectoryPath.CombineWithFilePath("inspectCode.log");

var settings = new InspectCodeSettings() {
OutputFile = inspectCodeLogFilePath,
ArgumentCustomization = x => x.Append("--no-build"),
WorkingDirectory = context.State.ProjectRootDirectory
};

context.InspectCode(
context.State.SolutionFilePath,
settings);

// Pass path to InspectCode log file to Cake.Frosting.Issues.Recipe.
context.Parameters.InputFiles.AddInspectCodeLogFile(inspectCodeLogFilePath);
}
}

[TaskName("Lint")]
[IsDependentOn(typeof(RunInspectCodeTask))]
[IsDependeeOf(typeof(ReadIssuesTask))]
public class LintTask : FrostingTask
{
}

[TaskName("Default")]
[IsDependentOn(typeof(IssuesTask))]
public class DefaultTask : FrostingTask
{
}
14 changes: 14 additions & 0 deletions tests/frosting/net8.0/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="packages" />
</config>
<packageSources>
<clear />
<add key="Integration" value="../../../BuildArtifacts/Packages/NuGet" />
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
22 changes: 22 additions & 0 deletions tests/frosting/net8.0/src/ClassLibrary1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{9B73BB5B-06A3-46F3-9068-E3607A8217B0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions tests/frosting/net8.0/src/ClassLibrary1/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
public class Class1
{
public void Foo()
{
var foo = "foo";
var bar = "bar";
if (!string.IsNullOrEmpty(foo) && !string.IsNullOrEmpty(bar))
{
var foobar = foo + bar;
}
}

public void Bar()
{
var foo = "foo";
var bar = "bar";
if (!string.IsNullOrEmpty(foo) && !string.IsNullOrEmpty(bar))
{
var foobar = foo + bar;
}
}
}
}
21 changes: 21 additions & 0 deletions tests/frosting/net8.0/src/ClassLibrary1/ClassLibrary1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<PrivateAssets>all</PrivateAssets>
<Version>3.0.0</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<PrivateAssets>all</PrivateAssets>
<Version>1.1.118</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>

0 comments on commit fe532fe

Please sign in to comment.