From f05ff2492bac283fa0f2c32ea701009324409f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Thu, 22 Feb 2024 18:32:52 -0500 Subject: [PATCH] Use mono on linux --- Build.ps1 | 1 - .../PackageFixture.cs | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index ee95466..1a08e8e 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -31,7 +31,6 @@ Process { Exec { & nuget pack Workleap.DotNet.CodingStandards.nuspec -OutputDirectory $outputDir -Version $version -ForceEnglishOutput } # Run tests - Get-Command nuget Exec { & dotnet test } # Push to a NuGet feed if the environment variables are set diff --git a/tests/Workleap.DotNet.CodingStandards.Tests/PackageFixture.cs b/tests/Workleap.DotNet.CodingStandards.Tests/PackageFixture.cs index 8d8e325..0af15b7 100644 --- a/tests/Workleap.DotNet.CodingStandards.Tests/PackageFixture.cs +++ b/tests/Workleap.DotNet.CodingStandards.Tests/PackageFixture.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using CliWrap; using Meziantou.Framework; using Workleap.DotNet.CodingStandards.Tests.Helpers; @@ -12,19 +13,32 @@ public sealed class PackageFixture : IAsyncLifetime public async Task InitializeAsync() { - // On CI the exe is already present - var exe = "nuget"; + var nuspecPath = PathHelpers.GetRootDirectory() / "Workleap.DotNet.CodingStandards.nuspec"; + string[] args = ["pack", nuspecPath, "-ForceEnglishOutput", "-Version", "999.9.9", "-OutputDirectory", _packageDirectory.FullPath]; + if (OperatingSystem.IsWindows()) { - var downloadPath = FullPath.GetTempPath() / $"nuget-{Guid.NewGuid()}.exe"; - await DownloadFileAsync("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", downloadPath); - exe = downloadPath; + var exe = FullPath.GetTempPath() / $"nuget-{Guid.NewGuid()}.exe"; + await DownloadFileAsync("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", exe); + + await Cli.Wrap(exe) + .WithArguments(args) + .ExecuteAsync(); } + else + { + // CliWrap doesn't support UseShellExecute. On Linux, it's easier to use it as "nuget" is a shell script that use mono to run nuget.exe + var psi = new ProcessStartInfo("nuget"); + foreach (var arg in args) + { + psi.ArgumentList.Add(arg); + } - var nuspecPath = PathHelpers.GetRootDirectory() / "Workleap.DotNet.CodingStandards.nuspec"; - await Cli.Wrap(exe) - .WithArguments(["pack", nuspecPath, "-ForceEnglishOutput", "-Version", "999.9.9", "-OutputDirectory", _packageDirectory.FullPath]) - .ExecuteAsync(); + var p = Process.Start(psi); + await p.WaitForExitAsync(); + if (p.ExitCode != 0) + throw new Exception("Error when running creating the NuGet package"); + } } public async Task DisposeAsync()