param( [string]$MSBuildPath, [switch]$Test ) $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest Push-Location $PSScriptRoot try { if (!$MSBuildPath) { $command = Get-Command MSBuild.exe -ErrorAction SilentlyContinue if ($command) { $MSBuildPath = $command.Source } else { $rider = Get-ChildItem "${env:ProgramFiles}/JetBrains" -Filter 'JetBrains Rider *' -Directory -ErrorAction SilentlyContinue | Sort-Object Name -Descending | Select-Object -First 1 if ($rider) { $MSBuildPath = Join-Path $rider.FullName 'tools/MSBuild/Current/Bin/MSBuild.exe' } } } if (!$MSBuildPath -or !(Test-Path -LiteralPath $MSBuildPath)) { throw 'Pass -MSBuildPath with Visual Studio or Rider MSBuild.exe.' } if (!(Test-Path -LiteralPath 'packages/net48/build/.NETFramework/v4.8/mscorlib.dll')) { New-Item -ItemType Directory -Force -Path 'packages/net48' | Out-Null $archive = Join-Path $PSScriptRoot 'packages/net48/package.zip' Invoke-WebRequest 'https://api.nuget.org/v3-flatcontainer/microsoft.netframework.referenceassemblies.net48/1.0.3/microsoft.netframework.referenceassemblies.net48.1.0.3.nupkg' -OutFile $archive Expand-Archive -LiteralPath $archive -DestinationPath 'packages/net48' -Force Remove-Item -LiteralPath $archive } & $MSBuildPath BlockMelonLoader.csproj /restore '/t:Rebuild,Pack' /p:Configuration=Release /v:minimal /nologo if ($LASTEXITCODE -ne 0) { throw 'Library build failed.' } if ($Test) { & $MSBuildPath Tests/BlockMelonLoader.Tests.csproj /t:Rebuild /v:minimal /nologo if ($LASTEXITCODE -ne 0) { throw 'Test build failed.' } & ./Tests/bin/Release/BlockMelonLoader.Tests.exe if ($LASTEXITCODE -ne 0) { throw 'Tests failed.' } } Write-Host "Library output: $PSScriptRoot/bin/Release/BlockMelonLoader.dll" Write-Host "NuGet output: $PSScriptRoot/artifacts/BlockMelonLoader.1.0.0.nupkg" } finally { Pop-Location }