-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathrnw-dependencies.ps1
More file actions
726 lines (629 loc) · 24.1 KB
/
Copy pathrnw-dependencies.ps1
File metadata and controls
726 lines (629 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# Troubleshoot RNW dependencies
param(
[switch]$Install = $false,
[switch]$NoPrompt = $false,
[switch]$Clone = $false,
[switch]$ListChecks = $false,
[string]$Check = [CheckId]::All,
[Parameter(ValueFromRemainingArguments)]
[ValidateSet('appDev', 'rnwDev', 'buildLab', 'vs2026', 'clone')]
[String[]]$Tags = @('appDev'),
[switch]$Enterprise = $false
)
$ShellInvocation = ($PSCmdlet.MyInvocation.BoundParameters -ne $null);
$Verbose = $false
if ($ShellInvocation) {
$Verbose = $PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent;
}
enum CheckId {
All
AzureFunctions
DeveloperMode
DotNetCore
FreeSpace
git
InstalledMemory
LongPath
MSBuildLogViewer
Node
RNWClone
VSUWP
WinAppDriver
WindowsADK
WindowsVersion
Yarn
CppWinRTVSIX
}
# CODESYNC \packages\@react-native-windows\cli\src\runWindows\runWindows.ts
$MarkerFile = "$env:LOCALAPPDATA\rnw-dependencies.txt"
# Create a set to handle with case insensitivy of the tags
$tagsToInclude = New-Object System.Collections.Generic.HashSet[string]([System.StringComparer]::OrdinalIgnorecase)
foreach ($tag in $Tags) { $tagsToInclude.Add($tag) | Out-null }
# Convert legacy flags to tasks:
if ($Clone) {
$tagsToInclude.Add('clone') | Out-null;
}
# Handle expansion of tasks
if ($tagsToInclude.Contains('buildLab')) {
# The build lab needs the same steps as a react-native dev
$tagsToInclude.Add('rnwDev') | Out-null;
}
if ($tagsToInclude.Contains('rnwDev')) {
# A react-native dev needs the same as the default
$tagsToInclude.Add('appDev') | Out-null;
}
# Detect processor architecture to select appropriate VC Tools component
$ProcessorArchitecture = $Env:Processor_Architecture
# Getting $Env:Processor_Architecture on arm64 machines will return x86. So check if the environment
# variable "ProgramFiles(Arm)" is also set, if it is we know the actual processor architecture is arm64.
# The value will also be x86 on amd64 machines when running the x86 version of PowerShell.
if ($ProcessorArchitecture -eq "x86")
{
if ($null -ne ${Env:ProgramFiles(Arm)})
{
$ProcessorArchitecture = "arm64"
}
elseif ($null -ne ${Env:ProgramFiles(x86)})
{
$ProcessorArchitecture = "amd64"
}
}
# Select the appropriate VC Tools component based on processor architecture
if ($ProcessorArchitecture -eq "arm64")
{
$vcToolsComponent = 'Microsoft.VisualStudio.Component.VC.Tools.ARM64'
}
else
{
$vcToolsComponent = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
}
$vsComponents = @('Microsoft.Component.MSBuild',
$vcToolsComponent,
'Microsoft.VisualStudio.ComponentGroup.UWP.Support',
'Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core',
'Microsoft.VisualStudio.Component.Windows10SDK.19041',
'Microsoft.VisualStudio.Component.Windows11SDK.22621');
# UWP.VC is not needed to build the projects with msbuild, but the VS IDE requires it.
if (!($tagsToInclude.Contains('buildLab'))) {
$vsComponents += 'Microsoft.VisualStudio.ComponentGroup.UWP.VC';
}
$vsWorkloads = @('Microsoft.VisualStudio.Workload.ManagedDesktop',
'Microsoft.VisualStudio.Workload.NativeDesktop',
'Microsoft.VisualStudio.Workload.Universal');
$vsAll = ($vsComponents + $vsWorkloads);
# The minimum winget version to check for
$wingetver = "1.7.11261";
# The minimum VS version to check for
# Note: For install to work, whatever min version you specify here must be met by the current package available on winget.
$vsver = "18.0.0";
# The exact .NET SDK version to check for
$dotnetver = "8.0";
# Version name of the winget package
$wingetDotNetVer = "8";
$v = [System.Environment]::OSVersion.Version;
if ($env:Agent_BuildDirectory) {
$drive = (Resolve-Path $env:Agent_BuildDirectory).Drive;
} else {
if ($PSCommandPath) {
$drive = (Resolve-Path $PSCommandPath).Drive;
} else {
$drive = (Resolve-Path $env:SystemDrive).Drive;
}
}
function Get-VSWhere {
Write-Verbose "Looking for Visual Studio Installer...";
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe";
if (!(Test-Path $vsWhere)) {
Write-Verbose "Visual Studio Installer not found.";
return $null;
}
Write-Verbose "Visual Studio Installer found.";
return $vsWhere;
}
function Get-VSPathPropertyForEachInstall {
param(
[string]$VsWhere,
[string]$PathProperty,
[string[]]$ExtraArgs =@()
)
[String[]]$output = & $VsWhere -version $vsver -property $PathProperty $ExtraArgs;
if ($output -ne $null) {
[String[]]$paths = ($output | Where-Object { (Test-Path $_) });
return $paths;
}
return $null;
}
function CheckVS-WithVSWhere {
param(
[string]$VsWhere,
[switch]$CheckPreRelease = $false
)
[string[]] $requireArgs = @("-requires");
$requireArgs += $vsAll;
[string[]] $prereleaseArgs = @();
if ($CheckPreRelease) {
$prereleaseArgs += "-prerelease";
}
# Checking for VS + all required components
[String[]]$productPaths = Get-VSPathPropertyForEachInstall -VsWhere $VsWhere -PathProperty 'productPath' -ExtraArgs ($requireArgs + $prereleaseArgs);
if ($productPaths.Count -gt 0) {
Write-Verbose "Visual Studio install(s) found, with required components, at:";
$productPaths | ForEach { Write-Verbose " $_" };
return $true;
}
# Check for VS without required components
[String[]]$productPaths = Get-VSPathPropertyForEachInstall -VsWhere $VsWhere -PathProperty 'productPath' -ExtraArgs $prereleaseArgs;
if ($productPaths.Count -gt 0) {
Write-Verbose "Visual Studio install(s) found, but without required components, at:";
$productPaths | ForEach { Write-Verbose " $_" };
return $false;
}
Write-Verbose "No Visual Studio installs found.";
return $false;
}
function CheckVS {
$vsWhere = Get-VSWhere;
if ($vsWhere -eq $null) {
return $false;
}
Write-Verbose "Looking for Visual Studio install(s)...";
[bool]$result = CheckVS-WithVSWhere -VsWhere $vsWhere;
if (!$result) {
Write-Verbose "Retrying, but also including pre-releases versions...";
[bool]$result = CheckVS-WithVSWhere -VsWhere $vsWhere -CheckPreRelease $true;
}
return $result;
}
function GetVSChannelAndProduct {
param(
[string]$VsWhere
)
if ($VsWhere) {
$channelId = & $VsWhere -version $vsver -property channelId;
$productId = & $VsWhere -version $vsver -property productId;
# Channel/product not found, check one more time for pre-release
if (($channelId -eq $null) -or ($productId -eq $null)) {
$channelId = & $VsWhere -version $vsver -property channelId -prerelease;
$productId = & $VsWhere -version $vsver -property productId -prerelease;
}
return $channelId, $productId;
}
return $null, $null;
}
function InstallVS {
$vsWhere = Get-VSWhere;
$channelId, $productId = GetVSChannelAndProduct -VsWhere $vsWhere
if (($vsWhere -eq $null) -or ($channelId -eq $null) -or ($productId -eq $null)) {
# No VSWhere / VS_Installer, try to install
if ($Enterprise) {
# The CI machines need the enterprise version of VS as that is what is hardcoded in all the scripts
WinGetInstall Microsoft.VisualStudio.2026.Enterprise
} else {
WinGetInstall Microsoft.VisualStudio.2026.Community
}
$vsWhere = Get-VSWhere;
$channelId, $productId = GetVSChannelAndProduct -VsWhere $vsWhere
}
# Final check before attempting install
if (($vsWhere -eq $null) -or ($channelId -eq $null) -or ($productId -eq $null)) {
throw "Unable to find or install a compatible version of Visual Studio >= ($vsver).";
}
$vsInstaller = Join-Path -Path (Split-Path -Parent $vsWhere) -ChildPath "vs_installer.exe";
$addWorkloads = $vsAll | % { '--add', $_ };
$p = Start-Process -PassThru -Wait -FilePath $vsInstaller -ArgumentList ("modify --channelId $channelId --productId $productId $addWorkloads --quiet --includeRecommended" -split ' ');
return $p.ExitCode;
}
function CheckNode {
try {
$nodeVersion = (Get-Command node -ErrorAction Stop).Version;
Write-Verbose "Node version found: $nodeVersion";
$major = $nodeVersion.Major;
$minor = $nodeVersion.Minor;
return ($major -gt 22) -or (($major -eq 22) -and ($minor -ge 14));
} catch { Write-Debug $_ }
Write-Verbose "Node not found.";
return $false;
}
function CheckYarn {
try {
$yarn = (Get-Command yarn -ErrorAction Stop);
if ($yarn -ne $null) {
$yarnVersion = & yarn -v;
Write-Verbose "Yarn version found: $yarnVersion";
return $true;
}
} catch { Write-Debug $_ }
Write-Verbose "Yarn not found.";
return $false;
}
function CheckWinAppDriver {
$WADPath = "${env:ProgramFiles(x86)}\Windows Application Driver\WinAppDriver.exe";
if (Test-Path $WADPath) {
$version = [Version]([System.Diagnostics.FileVersionInfo]::GetVersionInfo($WADPath).FileVersion);
Write-Verbose "WinAppDriver version found: $version";
return $version.CompareTo([Version]"1.2.1") -ge 0;
}
Write-Verbose "WinAppDriver not found.";
return $false;
}
function EnableDevmode {
$RegistryKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock";
if (-not(Test-Path -Path $RegistryKeyPath)) {
New-Item -Path $RegistryKeyPath -ItemType Directory -Force;
}
$value = get-ItemProperty -Path $RegistryKeyPath -Name AllowDevelopmentWithoutDevLicense -ErrorAction SilentlyContinue;
if (($value -eq $null) -or ($value.AllowDevelopmentWithoutDevLicense -ne 1)) {
Set-ItemProperty -Path $RegistryKeyPath -Name AllowDevelopmentWithoutDevLicense -Value 1 -ErrorAction Stop;
}
}
function CheckCppWinRT_VSIX {
$vsWhere = Get-VSWhere;
if ($vsWhere -eq $null) {
return $false;
}
[string]$vsPath = $null;
Write-Verbose "Looking for Visual Studio install(s)..."
[String[]]$vsPaths = Get-VSPathPropertyForEachInstall -VsWhere $VsWhere -PathProperty 'installationPath';
if ($vsPaths.Count -gt 0) {
Write-Verbose "Visual Studio install(s) found at:";
$vsPaths | ForEach { Write-Verbose " $_" }
$vsPath = $vsPaths[0];
}
if ($vsPath -eq $null) {
Write-Verbose "Retrying, but also including pre-releases versions..."
[String[]]$vsPaths = Get-VSPropertyForEachInstall -VsWhere $VsWhere -Property 'installationPath' -ExtraArgs @('-prerelease');
if ($vsPaths.Count -gt 0) {
Write-Verbose "Visual Studio install(s) found at:";
$vsPaths | ForEach { Write-Verbose " $_" }
$vsPath = $vsPaths[0];
}
}
if ($vsPath -ne $null) {
$natvis = Get-ChildItem (Join-Path -Path $vsPath -ChildPath "Common7\IDE\Extensions\cppwinrt.natvis") -Recurse;
if ($natvis -ne $null) {
Write-Verbose "Found CppWinRT VISX at:";
Write-Verbose " $(Split-Path $natvis)";
return $true;
}
}
Write-Verbose "CppWinRT VISX not found.";
return $false;
}
function InstallCppWinRT_VSIX {
$url = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/CppWinRTTeam/vsextensions/cppwinrt101804264/2.0.210304.5/vspackage";
Write-Verbose "Downloading CppWinRT VSIX from $url";
Invoke-WebRequest -UseBasicParsing $url -OutFile $env:TEMP\Microsoft.Windows.CppWinRT.vsix;
$vsWhere = Get-VSWhere;
if ($vsWhere -eq $null) {
return;
}
[string]$productPath = $null;
Write-Verbose "Looking for Visual Studio install(s)...";
[String[]]$productPaths = Get-VSPathPropertyForEachInstall -VsWhere $VsWhere -PathProperty 'productPath';
if ($productPaths.Count -gt 0) {
Write-Verbose "Visual Studio install(s) found at:";
$productPaths | ForEach { Write-Verbose " $_" };
$productPath = $productPaths[0];
}
if ($productPath -eq $null) {
Write-Verbose "Retrying, but also including pre-releases versions...";
[String[]]$productPaths = Get-VSPathPropertyForEachInstall -VsWhere $VsWhere -PathProperty 'productPath' -ExtraArgs @('-prerelease');
if ($productPaths.Count -gt 0) {
Write-Verbose "Visual Studio install(s) found at:";
$productPaths | ForEach { Write-Verbose " $_" };
$productPath = $productPaths[0];
}
}
$VSIXInstaller_exe = Join-Path (Split-Path $productPath) "VSIXInstaller.exe";
$process = Start-Process $VSIXInstaller_exe -PassThru -Wait -ArgumentList "/a /q $env:TEMP\Microsoft.Windows.CppWinRT.vsix";
$process.WaitForExit();
}
function CheckDotNetCore {
try {
$dotnet = (Get-Command dotnet.exe -ErrorAction Stop);
if ($dotnet -ne $null) {
Write-Verbose ".NET found, searching for SDKs...";
[string[]]$sdks = & dotnet --list-sdks;
if ($sdks -ne $null) {
Write-Verbose ".NET SDKs found:";
$sdks | ForEach { Write-Verbose " $_" };
$validSDKs = $sdks | Where-Object { $_ -like "$dotnetver.*"};
return ($validSDKs -ne $null) -and ($validSDKs.Length -ge 1);
}
}
} catch { Write-Debug $_ }
Write-Verbose ".NET not found.";
return $false;
}
$requiredFreeSpaceGB = 15;
$requirements = @(
@{
Id=[CheckId]::FreeSpace;
Name = "Free space on current drive > $requiredFreeSpaceGB GB";
Tags = @('appDev');
Valid = { $drive.Free/1GB -gt $requiredFreeSpaceGB; }
HasVerboseOutput = $true;
Optional = $true; # this requirement is fuzzy
},
@{
Id=[CheckId]::InstalledMemory;
Name = "Installed memory >= 16 GB";
Tags = @('appDev');
Valid = { (Get-CimInstance -ClassName win32_computersystem).TotalPhysicalMemory -gt 15GB; }
HasVerboseOutput = $true;
Optional = $true;
},
@{
Id=[CheckId]::WindowsVersion;
Name = 'Windows version >= 10.0.17763.0';
Tags = @('appDev');
Valid = { ($v.Major -eq 10 -and $v.Minor -eq 0 -and $v.Build -ge 16299); }
},
@{
Id=[CheckId]::DeveloperMode;
Name = 'Developer mode is on';
Tags = @('appDev');
Valid = { try { (Get-WindowsDeveloperLicense).IsValid } catch { $false }; }
Install = { EnableDevMode };
},
@{
Id=[CheckId]::LongPath;
Name = 'Long path support is enabled';
Tags = @('appDev');
Valid = { try { (Get-ItemProperty HKLM:/SYSTEM/CurrentControlSet/Control/FileSystem -Name LongPathsEnabled).LongPathsEnabled -eq 1} catch { $false }; }
Install = { Set-ItemProperty HKLM:/SYSTEM/CurrentControlSet/Control/FileSystem -Name LongPathsEnabled -Value 1 -Type DWord; };
},
@{
Id=[CheckId]::git;
Name = 'Git';
Tags = @('rnwDev');
Valid = { try { (Get-Command git.exe -ErrorAction Stop) -ne $null } catch { $false }; }
Install = { WinGetInstall Microsoft.Git };
},
@{
Id=[CheckId]::VSUWP;
Name = "Visual Studio 2026 (>= $vsver) & req. components";
Tags = @('appDev', 'vs2026');
Valid = { CheckVS; }
Install = { InstallVS };
HasVerboseOutput = $true;
},
@{
Id=[CheckId]::Node;
Name = 'Node.js (LTS, >= 22.0)';
Tags = @('appDev');
Valid = { CheckNode; }
Install = { WinGetInstall OpenJS.NodeJS.LTS "22.14.0" };
HasVerboseOutput = $true;
},
@{
Id=[CheckId]::Yarn;
Name = 'Yarn';
Tags = @('appDev');
Valid = { CheckYarn }
Install = { WinGetInstall Yarn.Yarn };
HasVerboseOutput = $true;
},
@{
Id=[CheckId]::WinAppDriver;
Name = 'WinAppDriver (>= 1.2.1)';
Tags = @('rnwDev');
Valid = { CheckWinAppDriver; }
Install = {
$ProgressPreference = 'Ignore';
$url = "https://github.com/microsoft/WinAppDriver/releases/download/v1.2.1/WindowsApplicationDriver_1.2.1.msi";
$downloadPath = "$env:TEMP\WindowsApplicationDriver.msi"
Write-Verbose "Downloading WinAppDriver from $url";
Invoke-WebRequest -UseBasicParsing $url -OutFile $downloadPath
# SDL Compliance: Verify signature (Work Item 58386093)
$signature = Get-AuthenticodeSignature $downloadPath
if ($signature.Status -ne "Valid") {
Remove-Item $downloadPath -ErrorAction SilentlyContinue
throw "WinAppDriver signature verification failed"
}
if ($signature.SignerCertificate.Subject -notlike "*Microsoft*") {
Remove-Item $downloadPath -ErrorAction SilentlyContinue
throw "WinAppDriver not signed by Microsoft"
}
& $downloadPath /q
Remove-Item $downloadPath -ErrorAction SilentlyContinue
};
HasVerboseOutput = $true;
Optional = $true;
},
@{
Id=[CheckId]::MSBuildLogViewer;
Name = "MSBuild Structured Log Viewer";
Tags = @('rnwDev');
Valid = { ( cmd "/c assoc .binlog 2>nul" ) -ne $null; }
Install = {
WinGetInstall KirillOsenkov.MSBuildStructuredLogViewer;
$slv = gci ${env:LocalAppData}\MSBuildStructuredLogViewer\StructuredLogViewer.exe -Recurse | select FullName | Sort-Object -Property FullName -Descending | Select-Object -First 1
cmd /c "assoc .binlog=MSBuildLog >nul";
cmd /c "ftype MSBuildLog=$($slv.FullName) %1 >nul";
};
Optional = $true;
},
@{
# Install the Windows ADK (Assessment and Deployment Kit) to install the wpt (Windows Performance Toolkit) so we can use wpr (Windows Performance Recorder) for performance analysis
Id=[CheckId]::WindowsADK;
Name = 'Windows ADK';
Tags = @('buildLab');
Valid = { (Test-Path "${env:ProgramFiles(x86)}\Windows Kits\10\Windows Performance Toolkit\wpr.exe"); };
Install = { WinGetInstall Microsoft.WindowsADK };
Optional = $true;
},
@{
Id=[CheckId]::RNWClone;
Name = "React-Native-Windows clone";
Tags = @('clone');
Valid = { try {
Test-Path -Path react-native-windows
} catch { $false }; }
Install = { & "${env:ProgramFiles}\Git\cmd\git.exe" clone https://github.com/microsoft/react-native-windows.git };
Optional = $true;
},
@{
Id=[CheckId]::CppWinRTVSIX;
Name = "C++/WinRT VSIX package";
Tags = @('rnwDev');
Valid = { CheckCppWinRT_VSIX; };
Install = { InstallCppWinRT_VSIX };
HasVerboseOutput = $true;
Optional = $true;
},
@{
ID=[CheckId]::DotNetCore;
Name = ".NET SDK (LTS, = $dotnetver)";
Tags = @('appDev');
Valid = { CheckDotNetCore; };
Install = { WinGetInstall Microsoft.DotNet.SDK.$wingetDotNetVer };
HasVerboseOutput = $true;
}
);
function InstallWinGet {
Write-Verbose "Updating WinGet version...";
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile "$env:TEMP\winget.msixbundle";
Add-AppPackage -ForceApplicationShutdown $env:TEMP\winget.msixbundle;
Remove-Item $env:TEMP\winget.msixbundle;
}
function EnsureWinGetForInstall {
Write-Verbose "Checking for WinGet...";
try {
# Check if winget.exe is in PATH
if (Get-Command "winget.exe" -CommandType Application -ErrorAction Ignore) {
Write-Verbose "WinGet found in PATH.";
Write-Verbose "Validating WinGet version...";
$wingetverfound = & winget -v;
if ([System.Version]$wingetverfound.Substring(1) -ge [System.Version]$wingetver ){
Write-Verbose "WinGet version found: $wingetverfound";
return;
}
}
InstallWinGet;
$installedwingetver = & winget -v;
Write-Verbose "WinGet version installed: $installedwingetver";
} catch { Write-Debug $_ }
}
function WinGetInstall {
param(
[string]$wingetPackage,
[string]$packageVersion = ""
)
EnsureWinGetForInstall;
if ($packageVersion -ne "") {
Write-Verbose "Executing `winget install `"$wingetPackage`" --version `"$packageVersion`"";
& winget install "$wingetPackage" --version "$packageVersion" --accept-source-agreements --accept-package-agreements
} else {
Write-Verbose "Executing `winget install `"$wingetPackage`"";
& winget install "$wingetPackage" --accept-source-agreements --accept-package-agreements
}
}
function IsElevated {
return [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544");
}
if (!($NoPrompt) -and !(IsElevated)) {
Write-Host "rnw-dependencies - this script must run elevated.";
if (!$ShellInvocation) { Read-Host 'Press Enter to exit' }
exit 1
}
$NeedsRerun = 0;
$Installed = 0;
$filteredRequirements = New-Object System.Collections.Generic.List[object];
foreach ($req in $requirements)
{
if ($Check -eq [CheckId]::All -or $req.Id -eq $Check)
{
foreach ($tag in $req.Tags)
{
if ($tagsToInclude.Contains($tag))
{
$filteredRequirements.Add($req);
break;
}
}
}
}
if ($ListChecks) {
foreach ($req in $filteredRequirements)
{
if ($req.Optional)
{
Write-Host -NoNewline Optional;
}
else
{
Write-Host -NoNewline Required;
}
Write-Host -NoNewline ": ";
Write-Host -NoNewline $req.Id;
Write-Host -NoNewline ": ";
Write-Host $req.Name;
}
return;
}
if (Test-Path $MarkerFile) {
Remove-Item $MarkerFile;
}
foreach ($req in $filteredRequirements)
{
Write-Host -NoNewline "Checking $($req.Name) ";
$resultPad = 60 - $req.Name.Length;
if ($req.HasVerboseOutput -and -$Verbose) {
# This makes sure the verbose output is one line lower
Write-Host "";
$resultPad = 70;
}
$valid = $false;
try {
$valid = Invoke-Command $req.Valid;
} catch {
Write-Warning "There was a problem checking for $($req.Name). Re-run with -Debug for details."
Write-Debug $_
}
if (!$valid) {
if ($req.Optional) {
Write-Host -ForegroundColor Yellow " Failed (warn)".PadLeft($resultPad);
}
else {
Write-Host -ForegroundColor Red " Failed".PadLeft($resultPad);
}
if ($req.Install) {
if ($Install -or (!$NoPrompt -and (Read-Host "Do you want to install? [y/N]").ToUpperInvariant() -eq 'Y')) {
try {
$LASTEXITCODE = 0;
$outputFromInstall = Invoke-Command $req.Install -ErrorAction Stop;
if ($LASTEXITCODE -ne 0) {
throw "Last exit code was non-zero: $LASTEXITCODE - $outputFromInstall";
}
$Installed++;
continue; # go to the next item
} catch {
Write-Warning "There was a problem trying to install $($req.Name). Re-run with -Debug for details."
Write-Debug $_
}
}
}
# If we got here, the req needed to be installed but wasn't
$NeedsRerun += !($req.Optional); # don't let failures from optional components fail the script
} else {
Write-Host -ForegroundColor Green " OK".PadLeft($resultPad);
}
}
if ($Installed -ne 0) {
Write-Host "Installed $Installed dependencies. You may need to close this window for changes to take effect.";
}
if ($NeedsRerun -ne 0) {
if ($Verbose) {
Write-Warning "Some dependencies are not met. Re-run with -Install to install them.";
} else {
Write-Warning "Some dependencies are not met. Re-run with -Verbose for details, or use -Install to install them.";
}
if (!$ShellInvocation) { Read-Host 'Press Enter to exit' }
exit 1;
} else {
Write-Host "All mandatory requirements met.";
$Tags | Out-File $MarkerFile;
if (!$ShellInvocation) { Read-Host 'Press Enter to exit' }
exit 0;
}