Skip to content
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"Pack",
"PackCoreOnly",
"Restore",
"SdkInstallation",
"Test",
"TestCoreOnly"
]
Expand All @@ -98,6 +99,7 @@
"Pack",
"PackCoreOnly",
"Restore",
"SdkInstallation",
"Test",
"TestCoreOnly"
]
Expand Down
90 changes: 85 additions & 5 deletions Build/Nuke/Build.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading.Channels;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
Expand All @@ -10,8 +15,10 @@
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Chocolatey;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.PowerShell;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
Expand Down Expand Up @@ -40,7 +47,6 @@
InvokedTargets = new[] { nameof(Test), nameof(TestCoreOnly), nameof(Pack) },
NonEntryTargets = new[] { nameof(Restore) },
ExcludedTargets = new[] { nameof(Clean), nameof(PackCoreOnly)})]

partial class Build : Nuke.Common.NukeBuild
{
/// Support plugins are available for:
Expand All @@ -59,15 +65,49 @@ partial class Build : Nuke.Common.NukeBuild
[GitVersion(Framework = "net5.0")] readonly GitVersion GitVersion;

[CI] readonly AzurePipelines AzurePipelines;


[CI] readonly GitHubActions GitHubActions;
AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath ResultDirectory => RootDirectory / ".result";
AbsolutePath PackagesDirectory => ResultDirectory / "packages";
AbsolutePath TestResultDirectory => ResultDirectory / "test-results";
IEnumerable<Project> TestProjects => Solution.GetProjects("*.Tests");
IEnumerable<Project> AllProjects => Solution.AllProjects.Where(x=> SourceDirectory.Contains(x.Path));

Target SdkInstallation => _ => _
.Before(Clean)
.Executes(() =>
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return;
Directory.CreateDirectory(ResultDirectory);
var ps1File = ResultDirectory / "donet-install.ps1";
using (var client = new HttpClient())
{
var bytes = client.GetByteArrayAsync(@"https://dot.net/v1/dotnet-install.ps1").Result;
File.WriteAllBytes(ps1File, bytes);
}

var channels = new[] {"2.1", "3.0", "3.1", "5.0"};
var architectures = new[] {"x86", "x64"};
var list = new List<(string chan, string arch)>();

foreach (var channel in channels)
{
foreach (var arch in architectures)
{
list.Add((channel, arch));
}
}

list.AsParallel()
.ForAll(x =>
{
var folder = ResultDirectory / x.chan / x.arch;
PowerShellTasks.PowerShell($" {ps1File} -Channel {x.chan} -Architecture {x.arch} -InstallDir {folder}");
});
});

Target Clean => _ => _
.Before(Restore)
.Executes(() =>
Expand All @@ -76,18 +116,43 @@ partial class Build : Nuke.Common.NukeBuild
});

Target Restore => _ => _
.DependsOn(SdkInstallation)
.Executes(() =>
{
var path = Environment.GetEnvironmentVariable("PATH");
var channels = new[] { "2.1", "3.0", "3.1", "5.0" };
var architectures = new[] { "x86", "x64" };
foreach (var channel in channels)
{
foreach (var architecture in architectures)
{
path += $";{ResultDirectory / channel / architecture}";
}
}

DotNetRestore(s => s
.SetProjectFile(Solution));
.SetProjectFile(Solution)
.AddProcessEnvironmentVariable("PATH", path));
});

Target Compile => _ => _
.DependsOn(Restore)
.Executes(() => ExecutesCompile(false));
.Executes(() =>
ExecutesCompile(false));

void ExecutesCompile(bool excludeNetFramework)
{
var path = Environment.GetEnvironmentVariable("PATH");
var channels = new[] { "2.1", "3.0", "3.1", "5.0" };
var architectures = new[] { "x86", "x64" };
foreach (var channel in channels)
{
foreach (var architecture in architectures)
{
path += $";{ResultDirectory / channel / architecture}";
}
}


Serilog.Log.Information(excludeNetFramework ? "Exclude net framework" : "Include net framework");
if (excludeNetFramework)
Expand All @@ -105,6 +170,7 @@ from platform in project.GetPlatforms()
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.AddProcessEnvironmentVariable("PATH", path)
.CombineWith(projectWithFrameworkAndPlatform, (s, f) => s
.SetFramework(f.framework)
.SetProperty("Platform", f.platform)
Expand All @@ -115,6 +181,7 @@ from platform in project.GetPlatforms()
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.AddProcessEnvironmentVariable("PATH", path)
.EnableNoRestore()
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
Expand All @@ -134,6 +201,18 @@ void ExecutesTest(bool excludeNetFramework)
{
Serilog.Log.Information(excludeNetFramework ? "Exclude net framework" : "Include net framework");

var path = Environment.GetEnvironmentVariable("PATH");
var channels = new[] { "2.1", "3.0", "3.1", "5.0" };
var architectures = new[] { "x86", "x64" };
foreach (var channel in channels)
{
foreach (var architecture in architectures)
{
path += $";{ResultDirectory / channel / architecture}";
}
}


var groupTestConfigurations =
(from project in TestProjects
from framework in project.GetTargetFrameworks(excludeNetFramework)
Expand All @@ -154,6 +233,7 @@ from platform in project.GetPlatformsForTests()
.SetConfiguration(Configuration)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetNoBuild(InvokedTargets.Contains(Compile))
.AddProcessEnvironmentVariable("PATH", path)
.ResetVerbosity()
.SetResultsDirectory(TestResultDirectory)
.CombineWith(testConfigurations, (_, v) => _
Expand Down