diff --git a/Directory.Build.props b/Directory.Build.props index 11951aed3..583b7f110 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - - - - - + + + + + diff --git a/UpdateNuGet.ps1 b/UpdateNuGet.ps1 new file mode 100644 index 000000000..f4582e6d8 --- /dev/null +++ b/UpdateNuGet.ps1 @@ -0,0 +1,152 @@ +#Requires -Version 5.1 +<# +.SYNOPSIS + Updates the Windows WDK and SDK NuGet package version referenced by + Directory.Build.props and packages.config. + +.DESCRIPTION + Rewrites the WDK/SDK NuGet version in both repo-root files so the whole + sample tree can be moved to a new WDK/SDK build with a single command. + + Only packages whose id starts with 'Microsoft.Windows.WDK' or + 'Microsoft.Windows.SDK' are touched. Any other package reference (for + example Microsoft.Windows.ImplementationLibrary) is left untouched. + + The files' existing encoding (BOM / no BOM) and line endings are preserved. + +.EXAMPLE + .\UpdateNuGet --package 10.0.28000.2525 + +.EXAMPLE + .\UpdateNuGet --package 10.0.28000.2525-preview + +.EXAMPLE + .\UpdateNuGet --package 10.0.28000.2525 --whatif +#> + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +function Show-Usage { + @' +Usage: .\UpdateNuGet --package [--whatif] + + --package, -p New WDK/SDK NuGet version. Examples: + 10.0.28000.2525 + 10.0.28000.2525-preview + --whatif Show what would change without writing any file. + --help, -h Show this help. +'@ | Write-Host +} + +# --- parse arguments --------------------------------------------------------- +$NewVersion = $null +$WhatIf = $false + +for ($i = 0; $i -lt $args.Count; $i++) { + $a = [string]$args[$i] + if ($a -match '^(?:--package|-package|-p)=(.+)$') { + $NewVersion = $Matches[1] + } + elseif ($a -match '^(?:--package|-package|-p)$') { + $i++ + if ($i -lt $args.Count) { $NewVersion = [string]$args[$i] } + else { throw "Missing value after '$a'." } + } + elseif ($a -match '^(?:--whatif|-whatif|-WhatIf)$') { + $WhatIf = $true + } + elseif ($a -match '^(?:--help|-help|-h|-\?|/\?)$') { + Show-Usage + return + } + elseif ($a -notmatch '^-' -and -not $NewVersion) { + $NewVersion = $a + } + else { + Show-Usage + throw "Unknown or unexpected argument: '$a'." + } +} + +if (-not $NewVersion) { + Show-Usage + throw "No version supplied. Pass --package ." +} + +# Allow a leading 'v' (v10.0.28000.2525) for convenience. +$NewVersion = $NewVersion.TrimStart('v', 'V') + +if ($NewVersion -notmatch '^\d+\.\d+\.\d+\.\d+(?:-[0-9A-Za-z.\-]+)?$') { + throw "Version '$NewVersion' does not look like a NuGet version " + + "(expected e.g. 10.0.28000.2525 or 10.0.28000.2525-preview)." +} + +# --- files to update --------------------------------------------------------- +$root = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path } + +$targets = @( + [pscustomobject]@{ + Path = Join-Path $root 'Directory.Build.props' + # packages\Microsoft.Windows.WDK.x64.\build\native\... + Pattern = [regex]'(Microsoft\.Windows\.(?:WDK|SDK)(?:\.CPP)?(?:\.(?:x64|x86|arm64|arm))?\.)(\d[0-9A-Za-z.\-]*?)(\\build\\native\\)' + }, + [pscustomobject]@{ + Path = Join-Path $root 'packages.config' + # + Pattern = [regex]'( {2} ({3} reference(s))" -f $name, ($oldVersions -join ', '), $NewVersion, $found.Count) + + if (-not $WhatIf) { + $enc = New-Object System.Text.UTF8Encoding($hasBom) + [System.IO.File]::WriteAllText($t.Path, $newText, $enc) + } + $anyChange = $true +} + +Write-Host "" +if ($WhatIf) { + Write-Host "WhatIf: no files were modified." -ForegroundColor Yellow +} +elseif ($anyChange) { + Write-Host "Done. WDK/SDK packages set to $NewVersion." -ForegroundColor Green + Write-Host "Next: restore packages (e.g. 'nuget restore' or 'msbuild -t:restore')." +} +else { + Write-Host "No changes were necessary." -ForegroundColor Green +} diff --git a/packages.config b/packages.config index d2a0bc5c0..4516da4ce 100644 --- a/packages.config +++ b/packages.config @@ -1,8 +1,8 @@  - - - - - + + + + +