/ src / modules / cmdpal / extensionsdk / nuget / BuildSDKHelper.ps1
BuildSDKHelper.ps1
  1  Param(
  2    [string]$Configuration = "release",
  3    [string]$VersionOfSDK = "",
  4    [string]$BuildStep = "all",
  5    [switch]$IsAzurePipelineBuild = $false,
  6    [switch]$Help = $false
  7  )
  8  
  9  If ([String]::IsNullOrEmpty($VersionOfSDK)) {
 10    $VersionOfSDK = $Env:XES_PACKAGEVERSIONNUMBER
 11  }
 12  
 13  If ([String]::IsNullOrEmpty($VersionOfSDK)) {
 14    $VersionOfSDK = "0.0.0"
 15  }
 16  
 17  $StartTime = Get-Date
 18  
 19  if ($Help) {
 20    Write-Host @"
 21  Copyright (c) Microsoft Corporation.
 22  Licensed under the MIT License.
 23  
 24  Syntax:
 25        Build.cmd [options]
 26  
 27  Description:
 28        Builds the Command Palette SDK
 29  
 30  Options:
 31  
 32    -Configuration <configuration>
 33        Only build the selected configuration(s)
 34        Example: -Configuration Release
 35        Example: -Configuration "Debug,Release"
 36  
 37    -VersionOfSDK <version>
 38        Set the version number of the build sdk nuget package
 39        Example: -VersionOfSDK "1.0.0"
 40  
 41    -Help
 42        Display this usage message.
 43  "@
 44    Exit
 45  }
 46  
 47  $ErrorActionPreference = "Stop"
 48  
 49  $buildPlatforms = "x64","arm64"
 50  
 51  $msbuildPath = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
 52  if ($IsAzurePipelineBuild) {
 53    $nugetPath = "nuget.exe";
 54  } else {
 55    $nugetPath = (Join-Path $PSScriptRoot "NugetWrapper.cmd")
 56  }
 57  $solutionPath = (Join-Path $PSScriptRoot "..\..\..\..\..\PowerToys.slnx")
 58  
 59  if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "build")) {
 60    $restoreArgs = @(
 61      $solutionPath
 62      "/t:Restore"
 63      "/p:RestorePackagesConfig=true"
 64    )
 65    & $msbuildPath $restoreArgs
 66  
 67    Try {
 68      foreach ($config in $Configuration.Split(",")) {
 69        foreach ($platform in $buildPlatforms) {
 70          $msbuildArgs = @(
 71            ("$PSScriptRoot\..\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj"),
 72            ("/p:Platform="+$platform),
 73            ("/p:Configuration="+$config),
 74            ("/binaryLogger:CmdPal.Extensions.$platform.$config.binlog"),
 75            ("/p:VersionNumber="+$VersionOfSDK)
 76            )
 77  
 78          if ($IsAzurePipelineBuild) {
 79            $msbuildArgs += "/p:CIBuild=true"
 80          }
 81  
 82          & $msbuildPath $msbuildArgs
 83        }
 84      }
 85    } Catch {
 86      $formatString = "`n{0}`n`n{1}`n`n"
 87      $fields = $_, $_.ScriptStackTrace
 88      Write-Host ($formatString -f $fields) -ForegroundColor RED
 89      Exit 1
 90    }
 91  }
 92  
 93  if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "pack")) {
 94    foreach ($config in $Configuration.Split(",")) {
 95      if ($config -eq "release")
 96      {
 97        New-Item -ItemType Directory -Force -Path "$PSScriptRoot\..\_build"
 98        & $nugetPath pack (Join-Path $PSScriptRoot "Microsoft.CommandPalette.Extensions.SDK.nuspec") -Version $VersionOfSDK -OutputDirectory "$PSScriptRoot\..\_build"
 99      } else {
100        Write-Host @"
101  WARNING: You are currently building as '$config' configuration.
102  CmdPalSDK nuget creation only supports 'release' configuration right now.
103  "@ -ForegroundColor YELLOW
104      }
105    }
106  }
107  
108  if ($IsAzurePipelineBuild) {
109    Write-Host "##vso[task.setvariable variable=VersionOfSDK;]$VersionOfSDK"
110    Write-Host "##vso[task.setvariable variable=VersionOfSDK;isOutput=true;]$VersionOfSDK"
111  }
112  
113  $TotalTime = (Get-Date)-$StartTime
114  $TotalMinutes = [math]::Floor($TotalTime.TotalMinutes)
115  $TotalSeconds = [math]::Ceiling($TotalTime.TotalSeconds)
116  
117  Write-Host @"
118  Total Running Time:
119  $TotalMinutes minutes and $TotalSeconds seconds
120  "@ -ForegroundColor CYAN