From 44b2c51605650ad9f97ae441991ab0454c7914d8 Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 02:31:31 +0100 Subject: [PATCH 1/8] [Infra] Try to use chocolatey to install net sdk. --- Build/Nuke/Build.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index a225b5a4..ed9d0eb0 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -10,6 +10,7 @@ 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.Utilities.Collections; @@ -59,8 +60,8 @@ 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"; @@ -68,6 +69,15 @@ partial class Build : Nuke.Common.NukeBuild IEnumerable TestProjects => Solution.GetProjects("*.Tests"); IEnumerable AllProjects => Solution.AllProjects.Where(x=> SourceDirectory.Contains(x.Path)); + Target SdkInstallation => _ => _ + .Before(Clean) + .Executes(() => + { + if (AzurePipelines == null && GitHubActions == null) + return; + ChocolateyTasks.Chocolatey(" install dotnetcore-sdk --version=3.0.103"); + }); + Target Clean => _ => _ .Before(Restore) .Executes(() => @@ -76,6 +86,7 @@ partial class Build : Nuke.Common.NukeBuild }); Target Restore => _ => _ + .DependsOn(SdkInstallation) .Executes(() => { DotNetRestore(s => s From aaec71800ca4c3317d1ec0f38240709682a98e99 Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 02:54:50 +0100 Subject: [PATCH 2/8] [Infra] increase timeout and not use chocolatey on linux. --- Build/Nuke/Build.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index ed9d0eb0..0370152c 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.CI.AzurePipelines; @@ -17,7 +18,7 @@ using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; -[CheckBuildProjectConfigurations] +[CheckBuildProjectConfigurations(TimeoutInMilliseconds = 2000)] [UnsetVisualStudioEnvironmentVariables] [GitHubActions( "continuous", @@ -41,7 +42,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: @@ -73,6 +73,8 @@ partial class Build : Nuke.Common.NukeBuild .Before(Clean) .Executes(() => { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return; if (AzurePipelines == null && GitHubActions == null) return; ChocolateyTasks.Chocolatey(" install dotnetcore-sdk --version=3.0.103"); From 3c97c95a0dba7edf8ca55aba4efb8c7001e67b76 Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 03:01:12 +0100 Subject: [PATCH 3/8] [Infra] Increase timeout --- Build/Nuke/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index 0370152c..7428f150 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -18,7 +18,7 @@ using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; -[CheckBuildProjectConfigurations(TimeoutInMilliseconds = 2000)] +[CheckBuildProjectConfigurations(TimeoutInMilliseconds = 20000)] [UnsetVisualStudioEnvironmentVariables] [GitHubActions( "continuous", From 16bc0dc970b0d86528a0437f5a4017a37ae584d2 Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 03:28:02 +0100 Subject: [PATCH 4/8] [Infra] Use dotnet-install.ps1 to install missing sdk. --- Build/Nuke/Build.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index 7428f150..0a8e8b97 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; using System.Runtime.InteropServices; using Nuke.Common; using Nuke.Common.CI; @@ -14,11 +16,12 @@ 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; -[CheckBuildProjectConfigurations(TimeoutInMilliseconds = 20000)] +[CheckBuildProjectConfigurations] [UnsetVisualStudioEnvironmentVariables] [GitHubActions( "continuous", @@ -77,7 +80,14 @@ partial class Build : Nuke.Common.NukeBuild return; if (AzurePipelines == null && GitHubActions == null) return; - ChocolateyTasks.Chocolatey(" install dotnetcore-sdk --version=3.0.103"); + var ps1File = ResultDirectory / "donet-install.ps1"; + using var client = new HttpClient(); + using (var s = client.GetStreamAsync(@"https://dot.net/v1/dotnet-install.ps1")) + { + using var fs = new FileStream(ps1File, FileMode.CreateNew); + s.Result.CopyTo(fs); + } + PowerShellTasks.PowerShell($" {ps1File} -Channel 3.0 -Architecture x86"); }); Target Clean => _ => _ From 7cbed5772e25d66b8f1851f50b7beec87a65fa60 Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 03:36:16 +0100 Subject: [PATCH 5/8] [Infra] Fix task running. --- Build/Nuke/Build.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index 0a8e8b97..54577296 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -81,9 +81,9 @@ partial class Build : Nuke.Common.NukeBuild if (AzurePipelines == null && GitHubActions == null) return; var ps1File = ResultDirectory / "donet-install.ps1"; - using var client = new HttpClient(); - using (var s = client.GetStreamAsync(@"https://dot.net/v1/dotnet-install.ps1")) + using (var client = new HttpClient()) { + using var s = client.GetStreamAsync(@"https://dot.net/v1/dotnet-install.ps1"); using var fs = new FileStream(ps1File, FileMode.CreateNew); s.Result.CopyTo(fs); } From 96391f17374a3953c1228f3b1bf1ffa3c7d57002 Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 03:58:08 +0100 Subject: [PATCH 6/8] [Infra] Try to fix download. --- Build/Nuke/Build.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index 54577296..fa478647 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -83,9 +83,8 @@ partial class Build : Nuke.Common.NukeBuild var ps1File = ResultDirectory / "donet-install.ps1"; using (var client = new HttpClient()) { - using var s = client.GetStreamAsync(@"https://dot.net/v1/dotnet-install.ps1"); - using var fs = new FileStream(ps1File, FileMode.CreateNew); - s.Result.CopyTo(fs); + var bytes = client.GetByteArrayAsync(@"https://dot.net/v1/dotnet-install.ps1").Result; + File.WriteAllBytes(ps1File, bytes); } PowerShellTasks.PowerShell($" {ps1File} -Channel 3.0 -Architecture x86"); }); From eebaaff15becf318bc00ca648b6b52533bff882c Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 1 Feb 2023 04:07:31 +0100 Subject: [PATCH 7/8] [Infra] Create directory. --- Build/Nuke/Build.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index fa478647..09ac7b66 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -80,6 +80,7 @@ partial class Build : Nuke.Common.NukeBuild return; if (AzurePipelines == null && GitHubActions == null) return; + Directory.CreateDirectory(ResultDirectory); var ps1File = ResultDirectory / "donet-install.ps1"; using (var client = new HttpClient()) { From 00df5b49c3d704e24e4257a119f7361c9d350cdb Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Fri, 3 Feb 2023 06:00:35 +0100 Subject: [PATCH 8/8] [Infra] try to add all sdk in path. --- .nuke/build.schema.json | 2 ++ Build/Nuke/Build.cs | 67 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index fdabac37..9760f7c7 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -77,6 +77,7 @@ "Pack", "PackCoreOnly", "Restore", + "SdkInstallation", "Test", "TestCoreOnly" ] @@ -98,6 +99,7 @@ "Pack", "PackCoreOnly", "Restore", + "SdkInstallation", "Test", "TestCoreOnly" ] diff --git a/Build/Nuke/Build.cs b/Build/Nuke/Build.cs index 09ac7b66..acdeae24 100644 --- a/Build/Nuke/Build.cs +++ b/Build/Nuke/Build.cs @@ -1,9 +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; @@ -78,8 +80,6 @@ partial class Build : Nuke.Common.NukeBuild { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; - if (AzurePipelines == null && GitHubActions == null) - return; Directory.CreateDirectory(ResultDirectory); var ps1File = ResultDirectory / "donet-install.ps1"; using (var client = new HttpClient()) @@ -87,7 +87,25 @@ partial class Build : Nuke.Common.NukeBuild var bytes = client.GetByteArrayAsync(@"https://dot.net/v1/dotnet-install.ps1").Result; File.WriteAllBytes(ps1File, bytes); } - PowerShellTasks.PowerShell($" {ps1File} -Channel 3.0 -Architecture x86"); + + 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 => _ => _ @@ -101,16 +119,40 @@ partial class Build : Nuke.Common.NukeBuild .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) @@ -128,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) @@ -138,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) @@ -157,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) @@ -177,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) => _