Skip to content

Commit

Permalink
Use mono on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Feb 22, 2024
1 parent a3428a5 commit f05ff24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 23 additions & 9 deletions tests/Workleap.DotNet.CodingStandards.Tests/PackageFixture.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using CliWrap;
using Meziantou.Framework;
using Workleap.DotNet.CodingStandards.Tests.Helpers;
Expand All @@ -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()
Expand Down

0 comments on commit f05ff24

Please sign in to comment.