From 8d18fcba9c756a590f781ae1baafc272167017b9 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Fri, 9 Apr 2021 09:06:40 +0530 Subject: [PATCH 1/3] Format Build related files Normalize Tabs into Spaces Clean-up trailing white-spaces Fix-up new-lines where necessary --- .gitattributes | 6 +++--- .runsettings | 2 +- azure-pipelines.yml | 12 ++++++------ build/Find-WindowsSDKVersions.ps1 | 12 ++++++------ build/Sign-Package.ps1 | 10 +++++----- build/build.cake | 3 --- nuget.config | 2 +- settings.xamlstyler | 4 ++-- stylecop.json | 14 +++++++------- version.json | 4 ++-- 10 files changed, 33 insertions(+), 36 deletions(-) diff --git a/.gitattributes b/.gitattributes index 1ff0c423042..5896c1692ee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,7 +17,7 @@ # # Merging from the command prompt will add diff markers to the files if there # are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following +# the diff markers are never inserted). Diff markers may cause the following # file extensions to fail to load in VS. An alternative would be to treat # these files as binary and thus will always conflict and require user # intervention with every merge. To do so, just uncomment the entries below @@ -46,9 +46,9 @@ ############################################################################### # diff behavior for common document formats -# +# # Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the +# is only available from the command line. Turn it on by uncommenting the # entries below. ############################################################################### #*.doc diff=astextplain diff --git a/.runsettings b/.runsettings index ff838beeafe..44f0672a141 100644 --- a/.runsettings +++ b/.runsettings @@ -1,6 +1,6 @@ - 0 + 0 0 ClassLevel diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 77b50e578cf..bd7f20b9423 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -11,14 +11,14 @@ pr: pool: vmImage: windows-2019 -variables: +variables: BuildConfiguration: Release jobs: ### BUILD ### - job: BuildBits timeoutInMinutes: 60 - + steps: - task: BatchScript@1 inputs: @@ -32,7 +32,7 @@ jobs: inputs: versionSpec: 5.6.0 - - task: DotNetCoreCLI@2 + - task: DotNetCoreCLI@2 inputs: command: custom custom: tool @@ -49,7 +49,7 @@ jobs: displayName: Build ### Unit Tests ### - + - powershell: .\build\build.ps1 -target=Test displayName: Test @@ -105,7 +105,7 @@ jobs: - job: SmokeTests dependsOn: BuildBits timeoutInMinutes: 60 - + steps: - task: DownloadPipelineArtifact@2 displayName: Download NuGet Packages Artifact @@ -113,7 +113,7 @@ jobs: artifact: Packages path: .\bin\nupkg - - task: DotNetCoreCLI@2 + - task: DotNetCoreCLI@2 inputs: command: custom custom: tool diff --git a/build/Find-WindowsSDKVersions.ps1 b/build/Find-WindowsSDKVersions.ps1 index ebb8ab5eeb1..ab6aa50e9aa 100644 --- a/build/Find-WindowsSDKVersions.ps1 +++ b/build/Find-WindowsSDKVersions.ps1 @@ -9,13 +9,13 @@ function Get-Nodes { param( [parameter(ValueFromPipeline=$true)] - [xml] $xml, + [xml] $xml, [parameter(Mandatory=$true)] [string] $nodeName) # Try the old style csproj. Also format required for .targets and .props files $n = Select-Xml -Xml $xml.Project -Namespace @{d = $ns } -XPath "//d:$nodeName" - + # Try the SDK-style files if (!$n) { $r = Select-Xml -Xml $xml.Project -XPath "//$nodeName" @@ -28,7 +28,7 @@ function Get-NodeValue { param( [parameter(ValueFromPipeline=$true)] - [xml] $xml, + [xml] $xml, [string] $nodeName) $node = get-nodes $xml $nodeName @@ -45,7 +45,7 @@ function Get-NodeValue function Get-SdkVersion { param( - [Parameter(ValueFromPipeline=$true)] $file) + [Parameter(ValueFromPipeline=$true)] $file) [xml] $xml = Get-Content $file @@ -150,7 +150,7 @@ foreach($version in $versions) { if ($version -match "10\.0\.\d{5}\.0") { $installRequired = Test-InstallWindowsSDK $version Write-Host "Windows SDK '$version' install required: $installRequired" - if ($installRequired) { + if ($installRequired) { # Automatically invoke Install-WindowsSDKIso.ps1 ? $anyInstallRequired = $true } @@ -158,7 +158,7 @@ foreach($version in $versions) { } Write-Host -if ($anyInstallRequired) { +if ($anyInstallRequired) { throw "At least one Windows SDK is missing from this machine" } else { Write-Host "All referenced Windows SDKs are installed!" diff --git a/build/Sign-Package.ps1 b/build/Sign-Package.ps1 index b1f53609213..d8def95e124 100644 --- a/build/Sign-Package.ps1 +++ b/build/Sign-Package.ps1 @@ -3,8 +3,8 @@ $currentDirectory = split-path $MyInvocation.MyCommand.Definition # See if we have the ClientSecret available if([string]::IsNullOrEmpty($Env:SignClientSecret)){ - Write-Host "Client Secret not found, not signing packages" - return; + Write-Host "Client Secret not found, not signing packages" + return; } dotnet tool install --tool-path . SignClient @@ -16,13 +16,13 @@ $appSettings = "$currentDirectory\SignClientSettings.json" $nupkgs = gci $Env:ArtifactDirectory\*.nupkg -recurse | Select -ExpandProperty FullName foreach ($nupkg in $nupkgs){ - Write-Host "Submitting $nupkg for signing" + 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' + .\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' if ($LASTEXITCODE -ne 0) { exit 1 } - Write-Host "Finished signing $nupkg" + Write-Host "Finished signing $nupkg" } Write-Host "Sign-package complete" \ No newline at end of file diff --git a/build/build.cake b/build/build.cake index db5dd4ec81a..14c3649c144 100644 --- a/build/build.cake +++ b/build/build.cake @@ -312,7 +312,6 @@ Task("MSTestUITest") DotNetCoreTest(file.FullPath, testSettings); }); - ////////////////////////////////////////////////////////////////////// // TASK TARGETS ////////////////////////////////////////////////////////////////////// @@ -353,8 +352,6 @@ Task("StyleXaml") } }); - - ////////////////////////////////////////////////////////////////////// // EXECUTION ////////////////////////////////////////////////////////////////////// diff --git a/nuget.config b/nuget.config index b96dd699a47..1b39cb3113e 100644 --- a/nuget.config +++ b/nuget.config @@ -8,4 +8,4 @@ - + \ No newline at end of file diff --git a/settings.xamlstyler b/settings.xamlstyler index 34c6ebee26c..443f4b5a084 100644 --- a/settings.xamlstyler +++ b/settings.xamlstyler @@ -7,7 +7,7 @@ "SeparateByGroups": false, "AttributeIndentation": 0, "AttributeIndentationStyle": 1, - "RemoveDesignTimeReferences": false, + "RemoveDesignTimeReferences": false, "EnableAttributeReordering": true, "AttributeOrderingRuleGroups": [ "x:Class", @@ -39,4 +39,4 @@ "FormatOnSave": true, "CommentPadding": 2, "IndentSize": 4 -} +} \ No newline at end of file diff --git a/stylecop.json b/stylecop.json index d839cca3309..7a611b82301 100644 --- a/stylecop.json +++ b/stylecop.json @@ -1,8 +1,8 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "orderingRules": { - "usingDirectivesPlacement": "outsideNamespace" - } +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "orderingRules": { + "usingDirectivesPlacement": "outsideNamespace" } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/version.json b/version.json index 0dbe7b20fbf..ca35973bffc 100644 --- a/version.json +++ b/version.json @@ -5,7 +5,7 @@ "^refs/heads/dev$", // we release out of dev "^refs/heads/rel/\\d+\\.\\d+\\.\\d+" // we also release branches starting with rel/N.N.N ], - "nugetPackageVersion":{ + "nugetPackageVersion": { "semVer": 2 }, "cloudBuild": { @@ -13,4 +13,4 @@ "enabled": false } } -} +} \ No newline at end of file From b741e3527f0d4ad3faf07b978ca671868954e240 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Fri, 9 Apr 2021 09:30:22 +0530 Subject: [PATCH 2/3] Upgrade Cake Build Runner - Update Build script - Upgrade Cake Runner - Upgrade modules, addins and tools --- azure-pipelines.yml | 10 +- build/StyleXaml.bat | 2 +- build/UpdateHeaders.bat | 2 +- build/build.cake | 16 +-- build/build.ps1 | 213 +++++++++++++++++++++++------------- build/tools/packages.config | 2 +- 6 files changed, 150 insertions(+), 95 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bd7f20b9423..030173cb6ee 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -45,12 +45,12 @@ jobs: #- powershell: .\build\Install-WindowsSdkISO.ps1 19041 # displayName: Insider SDK - - powershell: .\build\build.ps1 -target=Build + - powershell: .\build\build.ps1 -Target Build displayName: Build ### Unit Tests ### - - powershell: .\build\build.ps1 -target=Test + - powershell: .\build\build.ps1 -Target Test displayName: Test - task: PublishTestResults@2 @@ -62,7 +62,7 @@ jobs: ### UI Integration Tests ### - - powershell: .\build\build.ps1 -target=UITest + - powershell: .\build\build.ps1 -Target UITest displayName: UI Integration Tests - task: PublishPipelineArtifact@1 @@ -81,7 +81,7 @@ jobs: ### Package ### - - powershell: .\build\build.ps1 -target=Package + - powershell: .\build\build.ps1 -Target Package displayName: Package - task: PowerShell@2 @@ -123,7 +123,7 @@ jobs: - script: nbgv cloud displayName: Set Version - - powershell: .\build\build.ps1 -target=SmokeTest + - powershell: .\build\build.ps1 -Target SmokeTest displayName: SmokeTest - task: CopyFiles@2 diff --git a/build/StyleXaml.bat b/build/StyleXaml.bat index b03dcbd2aed..3ebd1ccde66 100644 --- a/build/StyleXaml.bat +++ b/build/StyleXaml.bat @@ -1,3 +1,3 @@ @ECHO OFF -PowerShell.exe -file "%~dp0build.ps1" -target=StyleXaml +PowerShell.exe -file "%~dp0build.ps1" -Target StyleXaml PAUSE \ No newline at end of file diff --git a/build/UpdateHeaders.bat b/build/UpdateHeaders.bat index 166ea21217a..55872778b6e 100644 --- a/build/UpdateHeaders.bat +++ b/build/UpdateHeaders.bat @@ -1,3 +1,3 @@ @ECHO OFF -PowerShell.exe -file "%~dp0build.ps1" -target=UpdateHeaders +PowerShell.exe -file "%~dp0build.ps1" -Target UpdateHeaders PAUSE \ No newline at end of file diff --git a/build/build.cake b/build/build.cake index 14c3649c144..82be1b88c10 100644 --- a/build/build.cake +++ b/build/build.cake @@ -1,10 +1,10 @@ -#module nuget:?package=Cake.LongPath.Module&version=0.7.0 +#module nuget:?package=Cake.LongPath.Module&version=1.0.1 -#addin nuget:?package=Cake.FileHelpers&version=3.2.1 -#addin nuget:?package=Cake.Powershell&version=0.4.8 -#addin nuget:?package=Cake.GitVersioning&version=3.3.37 +#addin nuget:?package=Cake.FileHelpers&version=4.0.1 +#addin nuget:?package=Cake.Powershell&version=1.0.1 +#addin nuget:?package=Cake.GitVersioning&version=3.4.220 -#tool nuget:?package=MSTest.TestAdapter&version=2.1.0 +#tool nuget:?package=MSTest.TestAdapter&version=2.2.5 #tool nuget:?package=vswhere&version=2.8.4 using System; @@ -94,7 +94,7 @@ void VerifyHeaders(bool Replace) if(!Replace && hasMissing) { - throw new Exception("Please run UpdateHeaders.bat or '.\\build.ps1 -target=UpdateHeaders' and commit the changes."); + throw new Exception("Please run UpdateHeaders.bat or '.\\build.ps1 -Target UpdateHeaders' and commit the changes."); } } @@ -259,7 +259,7 @@ Task("Test") { Configuration = "Release", NoBuild = true, - Logger = "trx;LogFilePrefix=VsTestResults", + Loggers = new[] { "trx;LogFilePrefix=VsTestResults" }, Verbosity = DotNetCoreVerbosity.Normal, ArgumentCustomization = arg => arg.Append($"-s {baseDir}/.runsettings"), }; @@ -306,7 +306,7 @@ Task("MSTestUITest") { Configuration = "Release", NoBuild = true, - Logger = "trx;LogFilePrefix=VsTestResults", + Loggers = new[] { "trx;LogFilePrefix=VsTestResults" }, Verbosity = DotNetCoreVerbosity.Normal }; DotNetCoreTest(file.FullPath, testSettings); diff --git a/build/build.ps1 b/build/build.ps1 index deed10851c4..18078054a26 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -13,19 +13,18 @@ This is a Powershell script to bootstrap a Cake build. This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) and execute your Cake build script with the parameters you provide. +.PARAMETER Script +The build script to execute. .PARAMETER Target The build script target to run. .PARAMETER Configuration The build configuration to use. .PARAMETER Verbosity Specifies the amount of information to be displayed. -.PARAMETER Experimental -Tells Cake to use the latest Roslyn release. -.PARAMETER WhatIf -Performs a dry run of the build script. -No tasks will be executed. -.PARAMETER Mono -Tells Cake to use the Mono scripting engine. +.PARAMETER ShowDescription +Shows description about tasks. +.PARAMETER DryRun +Performs a dry run. .PARAMETER SkipToolPackageRestore Skips restoring of packages. .PARAMETER ScriptArgs @@ -38,18 +37,41 @@ https://cakebuild.net [CmdletBinding()] Param( - [string]$Target = "Default", + [string]$Script, + [string]$Target, + [string]$Configuration, [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity = "Verbose", - [switch]$Experimental, - [Alias("DryRun","Noop")] - [switch]$WhatIf, - [switch]$Mono, + [string]$Verbosity, + [switch]$ShowDescription, + [Alias("WhatIf", "Noop")] + [switch]$DryRun, [switch]$SkipToolPackageRestore, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs ) +# This is an automatic variable in PowerShell Core, but not in Windows PowerShell 5.x +if (-not (Test-Path variable:global:IsCoreCLR)) { + $IsCoreCLR = $false +} + +# Attempt to set highest encryption available for SecurityProtocol. +# PowerShell will not set this by default (until maybe .NET 4.6.x). This +# will typically produce a message for PowerShell v2 (just an info +# message though) +try { + # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) + # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't + # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is + # installed (.NET 4.5 is an in-place upgrade). + # PowerShell Core already has support for TLS 1.2 so we can skip this if running in that. + if (-not $IsCoreCLR) { + [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 + } + } catch { + Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3' + } + [Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null function MD5HashFile([string] $filePath) { @@ -72,58 +94,60 @@ function MD5HashFile([string] $filePath) { $file.Dispose() } + + if ($md5 -ne $null) + { + $md5.Dispose() + } } } +function GetProxyEnabledWebClient +{ + $wc = New-Object System.Net.WebClient + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() + $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials + $wc.Proxy = $proxy + return $wc +} + Write-Host "Preparing to run build script..." if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } +if(!$Script){ + $Script = Join-Path $PSScriptRoot "build.cake" +} $TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" +$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" $NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -$MODULES_DIR = Join-Path $PSScriptRoot "tools/modules" +$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" -$MODULES_PACKAGES_CONFIG_MD5 = Join-Path $MODULES_DIR "packages.config.md5sum" - -# Should we use mono? -$UseMono = ""; -if($Mono.IsPresent) { - Write-Verbose -Message "Using the Mono based scripting engine." - $UseMono = "-mono" -} -# Should we use the new Roslyn? -$UseExperimental = ""; -if($Experimental.IsPresent -and !($Mono.IsPresent)) { - Write-Verbose -Message "Using experimental version of Roslyn." - $UseExperimental = "-experimental" -} - -# Is this a dry run? -$UseDryRun = ""; -if($WhatIf.IsPresent) { - $UseDryRun = "-dryrun" -} +$env:CAKE_PATHS_TOOLS = $TOOLS_DIR +$env:CAKE_PATHS_ADDINS = $ADDINS_DIR +$env:CAKE_PATHS_MODULES = $MODULES_DIR # Make sure tools folder exists if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type directory | out-null + New-Item -Path $TOOLS_DIR -Type Directory | Out-Null } -# Fix to force PS to use TLS12 -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - # Make sure that packages.config exist. if (!(Test-Path $PACKAGES_CONFIG)) { Write-Verbose -Message "Downloading packages.config..." - try { (New-Object System.Net.WebClient).DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + try { + $wc = GetProxyEnabledWebClient + $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) + } catch { Throw "Could not download packages.config." } } @@ -143,14 +167,26 @@ if (!(Test-Path $NUGET_EXE)) { if (!(Test-Path $NUGET_EXE)) { Write-Verbose -Message "Downloading NuGet.exe..." try { - (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + $wc = GetProxyEnabledWebClient + $wc.DownloadFile($NUGET_URL, $NUGET_EXE) } catch { Throw "Could not download NuGet.exe." } } +# These are automatic variables in PowerShell Core, but not in Windows PowerShell 5.x +if (-not (Test-Path variable:global:ismacos)) { + $IsLinux = $false + $IsMacOS = $false +} + # Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE +$env:NUGET_EXE = $NUGET_EXE +$env:NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { + "mono `"$NUGET_EXE`"" +} else { + "`"$NUGET_EXE`"" +} # Restore tools from NuGet? if(-Not $SkipToolPackageRestore.IsPresent) { @@ -158,15 +194,17 @@ if(-Not $SkipToolPackageRestore.IsPresent) { Set-Location $TOOLS_DIR # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + [string] $md5Hash = MD5HashFile $PACKAGES_CONFIG if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { Write-Verbose -Message "Missing or changed package.config hash..." - Remove-Item * -Recurse -Exclude packages.config,nuget.exe + Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery | + Remove-Item -Recurse -Force } Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" if ($LASTEXITCODE -ne 0) { Throw "An error occurred while restoring NuGet tools." @@ -175,58 +213,75 @@ if(-Not $SkipToolPackageRestore.IsPresent) { { $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" } - Write-Verbose -Message ($NuGetOutput | out-string) + Write-Verbose -Message ($NuGetOutput | Out-String) + Pop-Location } -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe at $CAKE_EXE" -} +# Restore addins from NuGet +if (Test-Path $ADDINS_PACKAGES_CONFIG) { + Push-Location + Set-Location $ADDINS_DIR + + Write-Verbose -Message "Restoring addins from NuGet..." + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occurred while restoring NuGet addins." + } -# Make sure modules folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $MODULES_DIR)) { - Write-Verbose -Message "Creating tools/modules directory..." - New-Item -Path $MODULES_DIR -Type directory | out-null + Write-Verbose -Message ($NuGetOutput | Out-String) + + Pop-Location } -# Restore modules from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) { +# Restore modules from NuGet +if (Test-Path $MODULES_PACKAGES_CONFIG) { Push-Location Set-Location $MODULES_DIR - # Check for changes in modules packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($MODULES_PACKAGES_CONFIG) - if((!(Test-Path $MODULES_PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $MODULES_PACKAGES_CONFIG_MD5 ))) { - Write-Verbose -Message "Missing or changed modules package.config hash..." - Remove-Item * -Recurse -Exclude packages.config,packages.config.md5sum,nuget.exe - } - Write-Verbose -Message "Restoring modules from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" if ($LASTEXITCODE -ne 0) { Throw "An error occurred while restoring NuGet modules." } - else - { - $md5Hash | Out-File $MODULES_PACKAGES_CONFIG_MD5 -Encoding "ASCII" - } - Write-Verbose -Message ($NuGetOutput | out-string) + + Write-Verbose -Message ($NuGetOutput | Out-String) + Pop-Location } -# Start Cake -$path = Split-Path -Parent $MyInvocation.MyCommand.Definition -$Script = "$path/build.cake" +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} -Write-Host "Bootstrapping Cake..." -Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" --bootstrap" -if ($LASTEXITCODE -ne 0) { - throw "An error occurred while bootstrapping Cake." +$CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { + "mono `"$CAKE_EXE`"" +} else { + "`"$CAKE_EXE`"" } + # Build an array (not a string) of Cake arguments to be joined later +$cakeArguments = @() +if ($Script) { $cakeArguments += "`"$Script`"" } +if ($Target) { $cakeArguments += "--target=`"$Target`"" } +if ($Configuration) { $cakeArguments += "--configuration=$Configuration" } +if ($Verbosity) { $cakeArguments += "--verbosity=$Verbosity" } +if ($ShowDescription) { $cakeArguments += "--showdescription" } +if ($DryRun) { $cakeArguments += "--dryrun" } +$cakeArguments += $ScriptArgs + +# Start Cake Write-Host "Running build script..." -Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" -exit $LASTEXITCODE \ No newline at end of file +Invoke-Expression "& $CAKE_EXE_INVOCATION $($cakeArguments -join " ")" +$cakeExitCode = $LASTEXITCODE + +# Clean up environment variables that were created earlier in this bootstrapper +$env:CAKE_PATHS_TOOLS = $null +$env:CAKE_PATHS_ADDINS = $null +$env:CAKE_PATHS_MODULES = $null + +# Return exit code +exit $cakeExitCode diff --git a/build/tools/packages.config b/build/tools/packages.config index c0ec5b2ffbe..4dc0269f530 100644 --- a/build/tools/packages.config +++ b/build/tools/packages.config @@ -1,3 +1,3 @@ - + \ No newline at end of file From 2444b55bf41c1a485379fa2c7e6307340da9de96 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Fri, 9 Apr 2021 09:43:27 +0530 Subject: [PATCH 3/3] Format PowerShell Scripts Using VSCode's PowerShell extension, format and refactor the scripts! --- build/Find-WindowsSDKVersions.ps1 | 60 +++++------- build/Install-WindowsSDK.ps1 | 12 ++- build/Install-WindowsSdkISO.ps1 | 152 +++++++++++------------------- build/Sign-Package.ps1 | 6 +- build/build.cake | 13 ++- build/build.ps1 | 8 +- 6 files changed, 100 insertions(+), 151 deletions(-) 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 }