diff --git a/build/Find-WindowsSDKVersions.ps1 b/build/Find-WindowsSDKVersions.ps1 index ab6aa50e9aa..2649ef7e4de 100644 --- a/build/Find-WindowsSDKVersions.ps1 +++ b/build/Find-WindowsSDKVersions.ps1 @@ -5,12 +5,11 @@ $ErrorActionPreference = 'Stop' # Unique set of Windows SDK versions referenced in files $versions = New-Object System.Collections.Generic.HashSet[System.String] -function Get-Nodes -{ +function Get-Nodes { param( - [parameter(ValueFromPipeline=$true)] + [parameter(ValueFromPipeline = $true)] [xml] $xml, - [parameter(Mandatory=$true)] + [parameter(Mandatory = $true)] [string] $nodeName) # Try the old style csproj. Also format required for .targets and .props files @@ -24,10 +23,9 @@ function Get-Nodes return $r } -function Get-NodeValue -{ +function Get-NodeValue { param( - [parameter(ValueFromPipeline=$true)] + [parameter(ValueFromPipeline = $true)] [xml] $xml, [string] $nodeName) @@ -42,10 +40,9 @@ function Get-NodeValue return [string]"" } -function Get-SdkVersion -{ +function Get-SdkVersion { param( - [Parameter(ValueFromPipeline=$true)] $file) + [Parameter(ValueFromPipeline = $true)] $file) [xml] $xml = Get-Content $file @@ -67,26 +64,22 @@ function Get-SdkVersion $versions.Add("10.0." + $version + ".0") | Out-Null } -function Test-RegistryPathAndValue -{ +function Test-RegistryPathAndValue { param ( - [parameter(Mandatory=$true)] + [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $path, - [parameter(Mandatory=$true)] + [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $value) - try - { - if (Test-Path $path) - { + try { + if (Test-Path $path) { Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null return $true } } - catch - { + catch { } return $false @@ -101,24 +94,18 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) { $WindowsSDKInstalledRegPath = "$WindowsSDKRegPath\$WindowsSDKVersion\Installed Options" - if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) - { + if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) { # A Windows SDK is installed # Is an SDK of our version installed with the options we need? - if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") - { + if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") { # It appears we have what we need. Double check the disk $sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey - if ($sdkRoot) - { - if (Test-Path $sdkRoot) - { + if ($sdkRoot) { + if (Test-Path $sdkRoot) { $refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion" - if (Test-Path $refPath) - { + if (Test-Path $refPath) { $umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion" - if (Test-Path $umdPath) - { + if (Test-Path $umdPath) { # Pretty sure we have what we need $retval = $false } @@ -131,13 +118,13 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) { return $retval } -if(!$PSScriptRoot){ +if (!$PSScriptRoot) { $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } Write-Host -NoNewline "Locating referenced Windows SDK versions..." -Get-ChildItem *.csproj -Recurse | ForEach-Object { get-sdkversion $_} +Get-ChildItem *.csproj -Recurse | ForEach-Object { get-sdkversion $_ } Get-ChildItem *.targets -Recurse | ForEach-Object { get-sdkversion $_ } Get-ChildItem *.props -Recurse | ForEach-Object { get-sdkversion $_ } @@ -146,7 +133,7 @@ Write-Host $anyInstallRequired = $false; -foreach($version in $versions) { +foreach ($version in $versions) { if ($version -match "10\.0\.\d{5}\.0") { $installRequired = Test-InstallWindowsSDK $version Write-Host "Windows SDK '$version' install required: $installRequired" @@ -160,6 +147,7 @@ foreach($version in $versions) { Write-Host if ($anyInstallRequired) { throw "At least one Windows SDK is missing from this machine" -} else { +} +else { Write-Host "All referenced Windows SDKs are installed!" } \ No newline at end of file diff --git a/build/Install-WindowsSDK.ps1 b/build/Install-WindowsSDK.ps1 index b664dffab03..afeb2db263a 100644 --- a/build/Install-WindowsSDK.ps1 +++ b/build/Install-WindowsSDK.ps1 @@ -1,6 +1,10 @@ -mkdir c:\winsdktemp -$client = new-object System.Net.WebClient -$client.DownloadFile("https://go.microsoft.com/fwlink/p/?linkid=870807","c:\winsdktemp\winsdksetup.exe") +$WinSdkTempDir = "C:\WinSdkTemp\" +$WinSdkSetupExe = "C:\WinSdkTemp\" + "WinSdkSetup.exe" -Start-Process -Wait "c:\winsdktemp\winsdksetup.exe" "/features OptionId.UWPCpp /q" \ No newline at end of file +mkdir $WinSdkTempDir + +$client = [System.Net.WebClient]::new() +$client.DownloadFile("https://go.microsoft.com/fwlink/p/?linkid=870807", $WinSdkSetupExe) + +Start-Process -Wait $WinSdkSetupExe "/features OptionId.UWPCpp /q" \ No newline at end of file diff --git a/build/Install-WindowsSdkISO.ps1 b/build/Install-WindowsSdkISO.ps1 index ea9cf034dda..b83a3de9b2f 100644 --- a/build/Install-WindowsSdkISO.ps1 +++ b/build/Install-WindowsSdkISO.ps1 @@ -1,6 +1,6 @@ [CmdletBinding()] -param([Parameter(Mandatory=$true)] - [string]$buildNumber) +param([Parameter(Mandatory = $true)] + [string]$buildNumber) # Ensure the error action preference is set to the default for PowerShell3, 'Stop' $ErrorActionPreference = 'Stop' @@ -14,11 +14,10 @@ $WindowsSDKInstalledRegPath = "$WindowsSDKRegPath\$WindowsSDKVersion\Installed O $StrongNameRegPath = "HKLM:\SOFTWARE\Microsoft\StrongName\Verification" $PublicKeyTokens = @("31bf3856ad364e35") -function Download-File -{ +function Download-File { param ([string] $outDir, - [string] $downloadUrl, - [string] $downloadName) + [string] $downloadUrl, + [string] $downloadName) $downloadPath = Join-Path $outDir "$downloadName.download" $downloadDest = Join-Path $outDir $downloadName @@ -26,21 +25,17 @@ function Download-File Write-Host -NoNewline "Downloading $downloadName..." - try - { + try { $webclient = new-object System.Net.WebClient $webclient.DownloadFile($downloadUrl, $downloadPath) } - catch [System.Net.WebException] - { + catch [System.Net.WebException] { Write-Host Write-Warning "Failed to fetch updated file from $downloadUrl" - if (!(Test-Path $downloadDest)) - { + if (!(Test-Path $downloadDest)) { throw "$downloadName was not found at $downloadDest" } - else - { + else { Write-Warning "$downloadName may be out of date" } } @@ -50,8 +45,7 @@ function Download-File $downloadDestTemp = $downloadPath; # Delete and rename to final dest - if (Test-Path -PathType Container $downloadDest) - { + if (Test-Path -PathType Container $downloadDest) { [System.IO.Directory]::Delete($downloadDest, $true) } @@ -61,20 +55,16 @@ function Download-File return $downloadDest } -function Get-ISODriveLetter -{ +function Get-ISODriveLetter { param ([string] $isoPath) $diskImage = Get-DiskImage -ImagePath $isoPath - if ($diskImage) - { + if ($diskImage) { $volume = Get-Volume -DiskImage $diskImage - if ($volume) - { + if ($volume) { $driveLetter = $volume.DriveLetter - if ($driveLetter) - { + if ($driveLetter) { $driveLetter += ":" return $driveLetter } @@ -84,15 +74,13 @@ function Get-ISODriveLetter return $null } -function Mount-ISO -{ +function Mount-ISO { param ([string] $isoPath) # Check if image is already mounted $isoDrive = Get-ISODriveLetter $isoPath - if (!$isoDrive) - { + if (!$isoDrive) { Mount-DiskImage -ImagePath $isoPath -StorageType ISO | Out-Null } @@ -100,84 +88,68 @@ function Mount-ISO Write-Verbose "$isoPath mounted to ${isoDrive}:" } -function Dismount-ISO -{ +function Dismount-ISO { param ([string] $isoPath) $isoDrive = (Get-DiskImage -ImagePath $isoPath | Get-Volume).DriveLetter - if ($isoDrive) - { + if ($isoDrive) { Write-Verbose "$isoPath dismounted" Dismount-DiskImage -ImagePath $isoPath | Out-Null } } -function Disable-StrongName -{ +function Disable-StrongName { param ([string] $publicKeyToken = "*") reg ADD "HKLM\SOFTWARE\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null - if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") - { + if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { reg ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null } } -function Test-Admin -{ +function Test-Admin { $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal $identity $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } -function Test-RegistryPathAndValue -{ +function Test-RegistryPathAndValue { param ( - [parameter(Mandatory=$true)] + [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $path, - [parameter(Mandatory=$true)] + [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $value) - try - { - if (Test-Path $path) - { + try { + if (Test-Path $path) { Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null return $true } } - catch - { + catch { } return $false } -function Test-InstallWindowsSDK -{ +function Test-InstallWindowsSDK { $retval = $true - if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) - { + if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) { # A Windows SDK is installed # Is an SDK of our version installed with the options we need? - if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") - { + if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") { # It appears we have what we need. Double check the disk $sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey - if ($sdkRoot) - { - if (Test-Path $sdkRoot) - { + if ($sdkRoot) { + if (Test-Path $sdkRoot) { $refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion" - if (Test-Path $refPath) - { + if (Test-Path $refPath) { $umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion" - if (Test-Path $umdPath) - { + if (Test-Path $umdPath) { # Pretty sure we have what we need $retval = $false } @@ -190,13 +162,10 @@ function Test-InstallWindowsSDK return $retval } -function Test-InstallStrongNameHijack -{ - foreach($publicKeyToken in $PublicKeyTokens) - { +function Test-InstallStrongNameHijack { + foreach ($publicKeyToken in $PublicKeyTokens) { $key = "$StrongNameRegPath\*,$publicKeyToken" - if (!(Test-Path $key)) - { + if (!(Test-Path $key)) { return $true } } @@ -206,51 +175,42 @@ function Test-InstallStrongNameHijack Write-Host -NoNewline "Checking for installed Windows SDK $WindowsSDKVersion..." $InstallWindowsSDK = Test-InstallWindowsSDK -if ($InstallWindowsSDK) -{ +if ($InstallWindowsSDK) { Write-Host "Installation required" } -else -{ +else { Write-Host "INSTALLED" } $StrongNameHijack = Test-InstallStrongNameHijack Write-Host -NoNewline "Checking if StrongName bypass required..." -if ($StrongNameHijack) -{ +if ($StrongNameHijack) { Write-Host "REQUIRED" } -else -{ +else { Write-Host "Done" } -if ($StrongNameHijack -or $InstallWindowsSDK) -{ - if (!(Test-Admin)) - { +if ($StrongNameHijack -or $InstallWindowsSDK) { + if (!(Test-Admin)) { Write-Host throw "ERROR: Elevation required" } } -if ($InstallWindowsSDK) -{ +if ($InstallWindowsSDK) { # Static(ish) link for Windows SDK # Note: there is a delay from Windows SDK announcements to availability via the static link $uri = "https://software-download.microsoft.com/download/sg/Windows_InsiderPreview_SDK_en-us_$($buildNumber)_1.iso"; - if ($env:TEMP -eq $null) - { + if ($null -eq $env:TEMP) { $env:TEMP = Join-Path $env:SystemDrive 'temp' } $winsdkTempDir = Join-Path $env:TEMP "WindowsSDK" - if (![System.IO.Directory]::Exists($winsdkTempDir)) - { + if (![System.IO.Directory]::Exists($winsdkTempDir)) { [void][System.IO.Directory]::CreateDirectory($winsdkTempDir) } @@ -260,41 +220,35 @@ if ($InstallWindowsSDK) $downloadFile = Download-File $winsdkTempDir $uri $file # TODO Check if zip, exe, iso, etc. - try - { + try { Write-Host -NoNewline "Mounting ISO $file..." Mount-ISO $downloadFile Write-Host "Done" $isoDrive = Get-ISODriveLetter $downloadFile - if (Test-Path $isoDrive) - { + if (Test-Path $isoDrive) { Write-Host -NoNewLine "Installing WinSDK..." $setupPath = Join-Path "$isoDrive" "WinSDKSetup.exe" Start-Process -Wait $setupPath "/features $WindowsSDKOptions /q" Write-Host "Done" } - else - { + else { throw "Could not find mounted ISO at ${isoDrive}" } } - finally - { + finally { Write-Host -NoNewline "Dismounting ISO $file..." - #Dismount-ISO $downloadFile + # Dismount-ISO $downloadFile Write-Host "Done" } } -if ($StrongNameHijack) -{ +if ($StrongNameHijack) { Write-Host -NoNewline "Disabling StrongName for Windows SDK..." - foreach($key in $PublicKeyTokens) - { + foreach ($key in $PublicKeyTokens) { Disable-StrongName $key } diff --git a/build/Sign-Package.ps1 b/build/Sign-Package.ps1 index d8def95e124..8509c018bdd 100644 --- a/build/Sign-Package.ps1 +++ b/build/Sign-Package.ps1 @@ -2,7 +2,7 @@ $currentDirectory = split-path $MyInvocation.MyCommand.Definition # See if we have the ClientSecret available -if([string]::IsNullOrEmpty($Env:SignClientSecret)){ +if ([string]::IsNullOrEmpty($Env:SignClientSecret)) { Write-Host "Client Secret not found, not signing packages" return; } @@ -13,9 +13,9 @@ dotnet tool install --tool-path . SignClient $appSettings = "$currentDirectory\SignClientSettings.json" -$nupkgs = gci $Env:ArtifactDirectory\*.nupkg -recurse | Select -ExpandProperty FullName +$nupkgs = Get-ChildItem $Env:ArtifactDirectory\*.nupkg -recurse | Select-Object -ExpandProperty FullName -foreach ($nupkg in $nupkgs){ +foreach ($nupkg in $nupkgs) { Write-Host "Submitting $nupkg for signing" .\SignClient 'sign' -c $appSettings -i $nupkg -r $Env:SignClientUser -s $Env:SignClientSecret -n 'Windows Community Toolkit' -d 'Windows Community Toolkit' -u 'https://developer.microsoft.com/en-us/windows/uwp-community-toolkit' diff --git a/build/build.cake b/build/build.cake index 82be1b88c10..9bfd2c7809f 100644 --- a/build/build.cake +++ b/build/build.cake @@ -176,13 +176,14 @@ Task("InheritDoc") .Does(() => { Information("\nDownloading InheritDoc..."); - var installSettings = new NuGetInstallSettings { + var installSettings = new NuGetInstallSettings + { ExcludeVersion = true, Version = inheritDocVersion, OutputDirectory = toolsDir }; - NuGetInstall(new []{"InheritDoc"}, installSettings); + NuGetInstall(new[] {"InheritDoc"}, installSettings); var args = new ProcessArgumentBuilder() .AppendSwitchQuoted("-b", baseDir) @@ -210,7 +211,8 @@ Task("Package") .Does(() => { // Invoke the pack target in the end - var buildSettings = new MSBuildSettings { + var buildSettings = new MSBuildSettings + { MaxCpuCount = 0 } .SetConfiguration("Release") @@ -334,12 +336,13 @@ Task("StyleXaml") .Does(() => { Information("\nDownloading XamlStyler..."); - var installSettings = new NuGetInstallSettings { + var installSettings = new NuGetInstallSettings + { ExcludeVersion = true, OutputDirectory = toolsDir }; - NuGetInstall(new []{"xamlstyler.console"}, installSettings); + NuGetInstall(new[] {"xamlstyler.console"}, installSettings); Func exclude_objDir = fileSystemInfo => !fileSystemInfo.Path.Segments.Contains("obj"); diff --git a/build/build.ps1 b/build/build.ps1 index 18078054a26..63a20a1f980 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -90,12 +90,12 @@ function MD5HashFile([string] $filePath) } finally { - if ($file -ne $null) + if ($null -ne $file) { $file.Dispose() } - if ($md5 -ne $null) + if ($null -ne $md5) { $md5.Dispose() } @@ -157,7 +157,7 @@ if (!(Test-Path $NUGET_EXE)) { Write-Verbose -Message "Trying to find nuget.exe in PATH..." $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 - if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + if ($null -ne $NUGET_EXE_IN_PATH -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName } @@ -175,7 +175,7 @@ if (!(Test-Path $NUGET_EXE)) { } # These are automatic variables in PowerShell Core, but not in Windows PowerShell 5.x -if (-not (Test-Path variable:global:ismacos)) { +if (-not (Test-Path variable:global:IsMacOS)) { $IsLinux = $false $IsMacOS = $false }