From 03bd6a8ffeba44599e88c098aeb94bdd5837df48 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Mon, 11 May 2020 17:22:03 -0700 Subject: [PATCH 01/10] add rnw-dependencies.ps1 --- vnext/Scripts/rnw-dependencies.ps1 | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 vnext/Scripts/rnw-dependencies.ps1 diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 new file mode 100644 index 00000000000..c9acc798093 --- /dev/null +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -0,0 +1,127 @@ +# Troubleshoot RNW dependencies +param([switch]$Install = $false) +$vsWorkloads = @( 'Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', 'Microsoft.VisualStudio.ComponentGroup.UWP.Support'); + +$v = [System.Environment]::OSVersion.Version; + +function CheckVS { + $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + if (!(Test-Path $vsWhere)) { + return $false; + } + $output = & $vsWhere -version 16 -requires $vsWorkloads -property productPath + return Test-Path $output; +} + +function InstallVS { + $installerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"; + $vsWhere = "$installerPath\vswhere.exe" + if (!(Test-Path $vsWhere)) { + # No VSWhere / VS_Installer + & choco install -y visualstudio2019community + } + $channelId = & $vsWhere -version 16 -property channelId + $productId = & $vsWhere -version 16 -property productId + $vsInstaller = "$installerPath\vs_installer.exe" + $addWorkloads = $vsWorkloads | % { '--add', $_ }; + Start-Process -PassThru -Wait -Path $vsInstaller -ArgumentList ("install --channelId $channelId --productId $productId $addWorkloads --quiet" -split ' ') + +} + +function CheckNode { + try { + $v = (Get-Command node).Version.Major + return $v -eq 12 -or $v -eq 13 + } catch { + return $false; + } +} + +function GetChocoPkgVersion{ + params([string]$packageId) + [version]$version = (& choco list --local-only $packageId -r -e).Substring($packageId.Length + 1); + return $version; +} + +$requirements = @( + @{ + Name = 'Disk space > 15 GB'; + Valid = (Get-PSDrive -PSProvider FileSystem -Name 'C').Free/1GB -gt 15 + }, + @{ + Name = 'Windows version > 10.0.16299.0'; + Valid = ($v.Major -eq 10 -and $v.Minor -eq 0 -and $v.Build -ge 16299) + }, + @{ + Name = 'Developer mode is on'; + Valid = try { (Get-WindowsDeveloperLicense).IsValid } catch { $false } + }, + @{ + Name = 'Choco'; + Valid = try { (Get-Command choco) -ne $null } catch { $false }; + Install = { + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + }; + }, + @{ + Name = 'VS 2019 with UWP and Desktop/C++'; + Valid = CheckVS + }, + @{ + Name = 'NodeJS 12 or 13 installed'; + Valid = CheckNode + Install = { choco install -y nodejs.install --version=12.9.1 } + }, + @{ + Name = 'Chrome'; + Valid = try { ((Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(Default)').VersionInfo).ProductMajorPart + } catch { $false } ; + Install = { choco install -y GoogleChrome } + }, + @{ + Name = 'Yarn'; + Valid = try { (Get-Command yarn) -ne $null } catch { $false }; + Install = { choco install -y yarn } + }, + @{ + Name = 'Appium'; + Valid = (Test-Path "${env:ProgramFiles}\Appium\Appium.exe"); + Install = { choco install -y Appium-desktop } + }, + @{ + Name = 'WinAppDriver'; + Valid = (Test-Path "${env:ProgramFiles(x86)}\Windows Application Driver\WinAppDriver.exe"); + Install = { choco install -y WinAppDriver } + } + + ); + +function IsElevated { + return [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"); +} + +if (!(IsElevated)) { + Write-Output "rnw-dependencies - this script must run elevated. Exiting."; + return; +} + +$NeedsRerun = $false +foreach ($req in $requirements) +{ + if (!($req.Valid)) { + Write-Output "Requirement failed: $($req.Name)" + if ($req.Install) { + if ($Install -or ((Read-Host "Do you want to install? ").ToUpperInvariant() -eq 'Y')) { + Invoke-Command $req.Install -ErrorAction Stop + if ($LASTEXITCODE -ne 0) { throw "Last exit code was non-zero: $LASTEXITCODE"; } + } else { + $NeedsRerun = $true + } + } + } +} + +if ($NeedsRerun) { + Write-Output "Some dependencies are not met. Re-run with -Install to install them."; +} \ No newline at end of file From 085493b0afb111ddb383da870e2d5d9097be96fc Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Mon, 11 May 2020 17:22:16 -0700 Subject: [PATCH 02/10] Change files --- ...tive-windows-2020-05-11-17-22-16-rnw-dependencies.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-2020-05-11-17-22-16-rnw-dependencies.json diff --git a/change/react-native-windows-2020-05-11-17-22-16-rnw-dependencies.json b/change/react-native-windows-2020-05-11-17-22-16-rnw-dependencies.json new file mode 100644 index 00000000000..c4d7af43b9f --- /dev/null +++ b/change/react-native-windows-2020-05-11-17-22-16-rnw-dependencies.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "add rnw-dependencies.ps1", + "packageName": "react-native-windows", + "email": "asklar@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-05-12T00:22:16.000Z" +} From 4cc59237d5a56b735e97be8803cbe9e46d6609e7 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Mon, 11 May 2020 20:40:48 -0700 Subject: [PATCH 03/10] --sln --- docs/building-rnw.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/building-rnw.md b/docs/building-rnw.md index 3dd61b188ae..7b09e5cbbbf 100644 --- a/docs/building-rnw.md +++ b/docs/building-rnw.md @@ -22,7 +22,7 @@ Note that react-native-windows is a monorepo and relies on monorepo tools like y There are two ways to run the app. In a fully managed easy way, or by manually running all the required steps: ## Automatic -The playground app can be run in a completely automatic way by using `react-native run-windows`. +The playground app can be run in a completely automatic way by using `react-native run-windows --sln windows\playground.sln`. If you haven't already, install the react-native-cli (One time only!) ```cmd @@ -33,7 +33,7 @@ Then ```cmd cd packages\playground -react-native run-windows +react-native run-windows --sln windows\playground.sln ``` ## Manual From 15d2b3fb70df75165a9afe524e05a6806f3cd279 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 18:48:24 -0700 Subject: [PATCH 04/10] run in CI --- .ado/windows-vs-pr.yml | 7 +++++++ vnext/Scripts/rnw-dependencies.ps1 | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.ado/windows-vs-pr.yml b/.ado/windows-vs-pr.yml index 3a9f922b1bd..5bdccb68324 100644 --- a/.ado/windows-vs-pr.yml +++ b/.ado/windows-vs-pr.yml @@ -65,6 +65,13 @@ jobs: clean: false submodules: false + - task: PowerShell@2 + displayName: "Check if this environment meets the development dependencies" + inputs: + targetType: filePath + filePath: $(Build.SourcesDirectory)\vnext\Scripts\rnw-dependencies.ps1 + arguments: -NoPrompt + - template: templates/build-rnw.yml parameters: yarnBuildCmd: build diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index c9acc798093..94161cb5eb4 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -1,8 +1,9 @@ # Troubleshoot RNW dependencies -param([switch]$Install = $false) +param([switch]$Install = $false, [switch]$NoPrompt = $false) $vsWorkloads = @( 'Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', 'Microsoft.VisualStudio.ComponentGroup.UWP.Support'); $v = [System.Environment]::OSVersion.Version; +$drive = (Resolve-Path $PSCommandPath).Drive function CheckVS { $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" @@ -43,10 +44,12 @@ function GetChocoPkgVersion{ return $version; } +$requiredFreeSpaceGB = 15; + $requirements = @( @{ - Name = 'Disk space > 15 GB'; - Valid = (Get-PSDrive -PSProvider FileSystem -Name 'C').Free/1GB -gt 15 + Name = "Free space on $drive`: > $requiredFreeSpaceGB GB"; + Valid = $drive.Free/1GB -gt $requiredFreeSpaceGB }, @{ Name = 'Windows version > 10.0.16299.0'; @@ -56,6 +59,10 @@ $requirements = @( Name = 'Developer mode is on'; Valid = try { (Get-WindowsDeveloperLicense).IsValid } catch { $false } }, + @{ + Name = 'git'; + Valid = try { (Get-Command git.exe) -ne $null } catch { $false } + } @{ Name = 'Choco'; Valid = try { (Get-Command choco) -ne $null } catch { $false }; @@ -112,16 +119,21 @@ foreach ($req in $requirements) if (!($req.Valid)) { Write-Output "Requirement failed: $($req.Name)" if ($req.Install) { - if ($Install -or ((Read-Host "Do you want to install? ").ToUpperInvariant() -eq 'Y')) { + if ($Install -or (!$NoPrompt -and (Read-Host "Do you want to install? ").ToUpperInvariant() -eq 'Y')) { Invoke-Command $req.Install -ErrorAction Stop if ($LASTEXITCODE -ne 0) { throw "Last exit code was non-zero: $LASTEXITCODE"; } } else { - $NeedsRerun = $true + $NeedsRerun = $true; } + } else { + $NeedsRerun = $true; } } } if ($NeedsRerun) { Write-Output "Some dependencies are not met. Re-run with -Install to install them."; -} \ No newline at end of file + exit 1; +} else { + exit 0; +} From dd000e31df5f67d88c0fcd168345978fa31865f9 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 18:52:57 -0700 Subject: [PATCH 05/10] print --- vnext/Scripts/rnw-dependencies.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index 94161cb5eb4..74dda17937c 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -116,8 +116,9 @@ if (!(IsElevated)) { $NeedsRerun = $false foreach ($req in $requirements) { + Write-Output "Checking $($req.Name)"; if (!($req.Valid)) { - Write-Output "Requirement failed: $($req.Name)" + Write-Output "Requirement failed: $($req.Name)"; if ($req.Install) { if ($Install -or (!$NoPrompt -and (Read-Host "Do you want to install? ").ToUpperInvariant() -eq 'Y')) { Invoke-Command $req.Install -ErrorAction Stop @@ -135,5 +136,6 @@ if ($NeedsRerun) { Write-Output "Some dependencies are not met. Re-run with -Install to install them."; exit 1; } else { + Write-Output "All requirements met"; exit 0; } From d4dc77aea2c54e0b9ad21a862568bdc52bba8279 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 18:56:24 -0700 Subject: [PATCH 06/10] desktop appium is optional --- vnext/Scripts/rnw-dependencies.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index 74dda17937c..bce7ee98c0b 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -94,7 +94,8 @@ $requirements = @( @{ Name = 'Appium'; Valid = (Test-Path "${env:ProgramFiles}\Appium\Appium.exe"); - Install = { choco install -y Appium-desktop } + Install = { choco install -y Appium-desktop }; + Optional = $true }, @{ Name = 'WinAppDriver'; @@ -123,7 +124,7 @@ foreach ($req in $requirements) if ($Install -or (!$NoPrompt -and (Read-Host "Do you want to install? ").ToUpperInvariant() -eq 'Y')) { Invoke-Command $req.Install -ErrorAction Stop if ($LASTEXITCODE -ne 0) { throw "Last exit code was non-zero: $LASTEXITCODE"; } - } else { + } elseif (!$req.Optional) { $NeedsRerun = $true; } } else { From 247481dccf7f40e9539e6b6ce01c1f8e162f1ebf Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 19:05:30 -0700 Subject: [PATCH 07/10] use agent directory --- vnext/Scripts/rnw-dependencies.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index bce7ee98c0b..f184c85b6f8 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -3,7 +3,13 @@ param([switch]$Install = $false, [switch]$NoPrompt = $false) $vsWorkloads = @( 'Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', 'Microsoft.VisualStudio.ComponentGroup.UWP.Support'); $v = [System.Environment]::OSVersion.Version; -$drive = (Resolve-Path $PSCommandPath).Drive +if ($env:Agent_BuildDirectory) { + $drive = (Resolve-Path $env:Agent_BuildDirectory).Drive +} else { + $drive = (Resolve-Path $PSCommandPath).Drive +} + + function CheckVS { $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" @@ -100,7 +106,7 @@ $requirements = @( @{ Name = 'WinAppDriver'; Valid = (Test-Path "${env:ProgramFiles(x86)}\Windows Application Driver\WinAppDriver.exe"); - Install = { choco install -y WinAppDriver } + Install = { choco install -y WinAppDriver }; } ); @@ -137,6 +143,6 @@ if ($NeedsRerun) { Write-Output "Some dependencies are not met. Re-run with -Install to install them."; exit 1; } else { - Write-Output "All requirements met"; + Write-Output "All mandatory requirements met"; exit 0; } From 6415a7130afc01643d13b549b185b588e7bfd922 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 19:09:44 -0700 Subject: [PATCH 08/10] 15GB is a ballpark estimate --- vnext/Scripts/rnw-dependencies.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index f184c85b6f8..868813c66f6 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -5,6 +5,7 @@ $vsWorkloads = @( 'Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Compone $v = [System.Environment]::OSVersion.Version; if ($env:Agent_BuildDirectory) { $drive = (Resolve-Path $env:Agent_BuildDirectory).Drive + Write-Output Using Drive from $env:Agent_BuildDirectory ($drive) } else { $drive = (Resolve-Path $PSCommandPath).Drive } @@ -55,7 +56,8 @@ $requiredFreeSpaceGB = 15; $requirements = @( @{ Name = "Free space on $drive`: > $requiredFreeSpaceGB GB"; - Valid = $drive.Free/1GB -gt $requiredFreeSpaceGB + Valid = $drive.Free/1GB -gt $requiredFreeSpaceGB; + Optional = $true # this requirement is fuzzy }, @{ Name = 'Windows version > 10.0.16299.0'; From 7d3a10e40eaf6fc2d8ae07638eb5de3b5efaefee Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 19:15:47 -0700 Subject: [PATCH 09/10] optional space --- vnext/Scripts/rnw-dependencies.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index 868813c66f6..05f3963dc91 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -136,7 +136,7 @@ foreach ($req in $requirements) $NeedsRerun = $true; } } else { - $NeedsRerun = $true; + $NeedsRerun = !($req.Optional); } } } From 9bf1bbbcecdafdef1996cddd67fc4a3ab0960df7 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 12 May 2020 19:18:41 -0700 Subject: [PATCH 10/10] . --- vnext/Scripts/rnw-dependencies.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/vnext/Scripts/rnw-dependencies.ps1 b/vnext/Scripts/rnw-dependencies.ps1 index 05f3963dc91..ab27b0519ff 100644 --- a/vnext/Scripts/rnw-dependencies.ps1 +++ b/vnext/Scripts/rnw-dependencies.ps1 @@ -5,13 +5,10 @@ $vsWorkloads = @( 'Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Compone $v = [System.Environment]::OSVersion.Version; if ($env:Agent_BuildDirectory) { $drive = (Resolve-Path $env:Agent_BuildDirectory).Drive - Write-Output Using Drive from $env:Agent_BuildDirectory ($drive) } else { $drive = (Resolve-Path $PSCommandPath).Drive } - - function CheckVS { $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" if (!(Test-Path $vsWhere)) {