|
| 1 | +<# |
| 2 | +
|
| 3 | +.SYNOPSIS |
| 4 | +Download and extract GDK NuGet based on edition number |
| 5 | +
|
| 6 | +.DESCRIPTION |
| 7 | +This script determines the NuGet package id to use based on the provided GDK edition number. It makes use of MSBuild PackageReference floating version numbers to do the restore operation. |
| 8 | +
|
| 9 | +.PARAMETER GDKEditionNumber |
| 10 | +The GDK edition number in the form of YYMMQQ. |
| 11 | +
|
| 12 | +.PARAMETER OutputDirectory |
| 13 | +Directory to write the packages into. Path should not already contain the packages. |
| 14 | +
|
| 15 | +#> |
| 16 | + |
| 17 | +param( |
| 18 | + [Parameter( |
| 19 | + Mandatory, |
| 20 | + Position = 0 |
| 21 | + )] |
| 22 | + [string]$GDKEditionNumber, |
| 23 | + [Parameter( |
| 24 | + Mandatory, |
| 25 | + Position = 1 |
| 26 | + )] |
| 27 | + [string]$OutputDirectory |
| 28 | +) |
| 29 | + |
| 30 | +# Validate output directory |
| 31 | +if ([string]::IsNullOrEmpty($OutputDirectory)) { |
| 32 | + Write-Error "##[error]Output Directory is required" -ErrorAction Stop |
| 33 | +} |
| 34 | + |
| 35 | +# Parse edition number |
| 36 | +if (-not ($GDKEditionNumber -match '^([0-9][0-9])([0-9][0-9])([0-9][0-9])$')) { |
| 37 | + Write-Error "##[error]This script requires a valid GDK edition number!" -ErrorAction Stop |
| 38 | +} |
| 39 | + |
| 40 | +$year = $Matches.1 |
| 41 | +$month = [int]$Matches.2 |
| 42 | +$qfe = [int]$Matches.3 |
| 43 | + |
| 44 | +if ($year -lt 21) |
| 45 | +{ |
| 46 | + Write-Error "##[error]Edition year not supported: 20$year" -ErrorAction Stop |
| 47 | +} |
| 48 | + |
| 49 | +if (($month -lt 1) -or ($month -gt 12)) |
| 50 | +{ |
| 51 | + Write-Error "##[error]Edition month not supported: $month" -ErrorAction Stop |
| 52 | +} |
| 53 | + |
| 54 | +if ($qfe -gt 0) { |
| 55 | + Write-Host ("##[debug]GDKEditionNumber = $GDKEditionNumber ({0} 20{1} QFE {2})" -f (Get-Culture).DateTimeFormat.GetMonthName($month), $year, $qfe) |
| 56 | +} |
| 57 | +else { |
| 58 | + Write-Host ("##[debug]GDKEditionNumber = $GDKEditionNumber ({0} 20{1})" -f (Get-Culture).DateTimeFormat.GetMonthName($month), $year) |
| 59 | +} |
| 60 | + |
| 61 | +# Verify NuGet tool is available |
| 62 | +$nuget = Get-Command nuget.exe -ErrorAction SilentlyContinue |
| 63 | +if (-Not $nuget) { |
| 64 | + Write-Error "##[error]Missing required nuget.exe tool" -ErrorAction Stop |
| 65 | +} |
| 66 | + |
| 67 | +# Determine NuGet package ID |
| 68 | +if ($GDKEditionNumber -ge 241000) { |
| 69 | + $PGDK_ID = "Microsoft.GDK.PC" |
| 70 | + $GDKX_ID = "Microsoft.GDK.Xbox" |
| 71 | +} |
| 72 | +else { |
| 73 | + Write-Error "##[error]Script supports October 2024 or later" -ErrorAction Stop |
| 74 | +} |
| 75 | + |
| 76 | +# Check that the package isn't already present |
| 77 | +$PGDK_DIR = [IO.Path]::Combine($OutputDirectory, $PGDK_ID) |
| 78 | +if (Test-Path $PGDK_DIR) { |
| 79 | + Write-Error "##[error]PC Package ID already exists!" -ErrorAction Stop |
| 80 | +} |
| 81 | + |
| 82 | +$GDKX_DIR = [IO.Path]::Combine($OutputDirectory, $GDKX_ID) |
| 83 | +if (Test-Path $GDKX_DIR) { |
| 84 | + Write-Error "##[error]Xbox Package ID already exists!" -ErrorAction Stop |
| 85 | +} |
| 86 | + |
| 87 | +# Restore Nuget packages using floating versions |
| 88 | +$propsfile = [IO.Path]::Combine( $PSScriptRoot , "gdkedition.props") |
| 89 | +$props = Get-Content -Path $propsfile |
| 90 | +$props = $props -replace '<GDKEditionNumber>.+</GDKEditionNumber>', ("<GDKEditionNumber>{0}</GDKEditionNumber>" -f $GDKEditionNumber) |
| 91 | +Set-Content -Path $propsfile -Value $props |
| 92 | + |
| 93 | +$nugetArgs = "restore RestoreGDK.proj -PackageSaveMode nuspec -packagesDirectory `"{0}`"" -f $OutputDirectory.TrimEnd('\') |
| 94 | +Write-Host "##[command]nuget $nugetArgs" |
| 95 | +$nugetrun = Start-Process -PassThru -Wait -FilePath $nuget.Path -WorkingDirectory $PSScriptRoot -ArgumentList $nugetArgs -NoNewWindow |
| 96 | +if ($nugetrun.ExitCode -gt 0) { |
| 97 | + Write-Error "##[error]nuget restore failed" -ErrorAction Stop |
| 98 | +} |
| 99 | + |
| 100 | +# Verify expected output of restore |
| 101 | +if (-Not (Test-Path $PGDK_DIR)) { |
| 102 | + Write-Error "##[error]Missing PC package after restore!" -ErrorAction Stop |
| 103 | +} |
| 104 | + |
| 105 | +if (-Not (Test-Path $GDKX_DIR)) { |
| 106 | + Write-Error "##[error]Missing Xbox package after restore!" -ErrorAction Stop |
| 107 | +} |
| 108 | + |
| 109 | +# Reduce path depth removing version folder |
| 110 | +$PGDK_VER = Get-ChildItem $PGDK_DIR |
| 111 | +if ($PGDK_VER.Count -ne 1) { |
| 112 | + Write-Error "##[error]Expected a single directory for the version!" -ErrorAction Stop |
| 113 | +} |
| 114 | + |
| 115 | +$content = Get-ChildItem $PGDK_VER.Fullname |
| 116 | +ForEach-Object -InputObject $content { Move-Item $_.Fullname -Destination $PGDK_DIR } |
| 117 | +Remove-Item $PGDK_VER.Fullname |
| 118 | + |
| 119 | +$GDKX_VER = Get-ChildItem $GDKX_DIR |
| 120 | +if ($GDKX_VER.Count -ne 1) { |
| 121 | + Write-Error "##[error]Expected a single directory for the version!" -ErrorAction Stop |
| 122 | +} |
| 123 | + |
| 124 | +$content = Get-ChildItem $GDKX_VER.Fullname |
| 125 | +ForEach-Object -InputObject $content { Move-Item $_.Fullname -Destination $GDKX_DIR } |
| 126 | +Remove-Item $GDKX_VER.Fullname |
| 127 | + |
| 128 | +Write-Host ("##[debug]PC Package ID: {0} Version: {1}" -f $PGDK_ID, $PGDK_VER) |
| 129 | +Write-Host ("##[debug]Xbox Package ID: {0} Version: {1}" -f $GDKX_ID, $GDKX_VER) |
| 130 | + |
| 131 | +# Read the nuspec files |
| 132 | +$PGDK_NUSPEC = New-Object xml |
| 133 | +$PGDK_NUSPEC.PreserveWhitespace = $true |
| 134 | +$PGDK_NUSPEC.Load([IO.Path]::Combine($PGDK_DIR, $PGDK_ID + ".nuspec")) |
| 135 | + |
| 136 | +$GDKX_NUSPEC = New-Object xml |
| 137 | +$GDKX_NUSPEC.PreserveWhitespace = $true |
| 138 | +$GDKX_NUSPEC.Load([IO.Path]::Combine($GDKX_DIR, $GDKX_ID + ".nuspec")) |
| 139 | + |
| 140 | +# Log results |
| 141 | +Write-Host "##[group]PC Nuget Package nuspec" |
| 142 | +Write-host $PGDK_NUSPEC.outerxml |
| 143 | +Write-Host "##[endgroup]" |
| 144 | + |
| 145 | +Write-Host "##[group]Xbox Nuget Package nuspec" |
| 146 | +Write-host $GDKX_NUSPEC.outerxml |
| 147 | +Write-Host "##[endgroup]" |
| 148 | + |
| 149 | +$id = $PGDK_NUSPEC.package.metadata.id |
| 150 | +Write-Host "##vso[task.setvariable variable=PCNuGetPackage;]$id" |
| 151 | + |
| 152 | +$id = $GDKX_NUSPEC.package.metadata.id |
| 153 | +Write-Host "##vso[task.setvariable variable=XboxNuGetPackage;]$id" |
| 154 | + |
| 155 | +$ver = $PGDK_NUSPEC.package.metadata.version |
| 156 | +Write-Host "##vso[task.setvariable variable=PCNuGetPackageVersion;]$ver" |
| 157 | + |
| 158 | +$ver = $GDKX_NUSPEC.package.metadata.version |
| 159 | +Write-Host "##vso[task.setvariable variable=XboxNuGetPackageVersion;]$ver" |
0 commit comments