-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-DotNetTool.ps1
More file actions
800 lines (652 loc) · 26.4 KB
/
Copy pathUpdate-DotNetTool.ps1
File metadata and controls
800 lines (652 loc) · 26.4 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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
function Update-DotNetTool
{
<#
.SYNOPSIS
Updates local or global .NET tools based on the current directory context.
.DESCRIPTION
Searches the specified directory and its parent directories for a local .NET
tool manifest at .config/dotnet-tools.json. In the default Auto scope, every
tool in that local manifest is updated when a manifest is found. When no local
manifest is found, every globally installed .NET tool for the current user is
updated.
Use -Scope Local or -Scope Global to explicitly choose which tool scope to
inspect or update. Use -ListOutdated to perform a read-only check that displays
only tools where the installed version differs from the latest version returned
by 'dotnet tool search' or the NuGet flat-container metadata fallback.
The function lists installed tools first and updates each package explicitly,
which provides per-tool status information and keeps behavior consistent across
.NET SDK versions. Cross-platform compatible with PowerShell 5.1+ on Windows,
macOS, and Linux. Requires the dotnet CLI to be installed and available in PATH.
.PARAMETER Path
The directory used to discover a local .NET tool manifest. Defaults to the
current directory. If no manifest is found in this directory or any parent
directory, global tools are updated.
.PARAMETER Scope
Controls which .NET tool scope is used:
- Auto : Use local tools when a local manifest exists; otherwise use global tools.
- Local : Require a local tool manifest and use local tools.
- Global : Use global tools even when a local tool manifest exists.
.PARAMETER ListOutdated
Displays only outdated tools and does not update anything. Latest versions are
resolved with 'dotnet tool search' first, then the NuGet flat-container metadata
API when the dotnet search command fails. Use -Scope to choose Local or Global
explicitly, or leave Scope as Auto to use local tools when a manifest exists.
.PARAMETER Prerelease
Includes prerelease packages when updating tools.
.PARAMETER Interactive
Allows dotnet to stop and wait for user input or action, such as completing
authentication for a package source.
.PARAMETER IgnoreFailedSources
Treats package source failures as warnings during tool updates.
.PARAMETER NoHttpCache
Prevents dotnet from using HTTP cache data during tool updates.
.PARAMETER DisableParallel
Prevents dotnet restore from restoring multiple projects in parallel during
tool updates.
.PARAMETER Framework
The target framework to use when updating each tool. Passed directly to
'dotnet tool update --framework'.
.PARAMETER AdditionalArgs
Additional arguments to pass directly to each 'dotnet tool update' invocation.
Use this for less common dotnet options such as --verbosity or --add-source.
.EXAMPLE
PS > Update-DotNetTool
Updates all local tools when a .config/dotnet-tools.json manifest exists in the
current directory tree; otherwise updates all global tools.
.EXAMPLE
PS > Update-DotNetTool -Path ~/src/myapp
Uses ~/src/myapp as the starting directory for local tool manifest discovery.
.EXAMPLE
PS > Update-DotNetTool -Scope Local
Updates local tools and throws if no local .NET tool manifest exists in the
current directory tree.
.EXAMPLE
PS > Update-DotNetTool -Scope Global
Updates globally installed .NET tools even when the current directory tree has
a local .NET tool manifest.
.EXAMPLE
PS > Update-DotNetTool -ListOutdated
Displays only outdated tools in the automatically selected local or global scope
without updating anything.
.EXAMPLE
PS > Update-DotNetTool -Scope Local -ListOutdated
Displays only outdated local tools from the nearest .NET tool manifest.
.EXAMPLE
PS > Update-DotNetTool -Verbose
Updates the appropriate local or global tools and writes detailed progress.
.EXAMPLE
PS > Update-DotNetTool -WhatIf
Shows which local or global tools would be updated without running updates.
.EXAMPLE
PS > Update-DotNetTool -Prerelease
Updates tools while allowing prerelease tool package versions.
.EXAMPLE
PS > Update-DotNetTool -Interactive
Updates tools and allows interactive package source authentication prompts.
.EXAMPLE
PS > Update-DotNetTool -IgnoreFailedSources
Updates tools while treating unavailable package sources as warnings.
.EXAMPLE
PS > Update-DotNetTool -NoHttpCache
Updates tools without using cached HTTP package metadata.
.EXAMPLE
PS > Update-DotNetTool -DisableParallel
Updates tools with parallel restore disabled.
.EXAMPLE
PS > Update-DotNetTool -Framework net10.0
Updates tools targeting the net10.0 framework.
.EXAMPLE
PS > Get-ChildItem -Path ~/src -Directory | Update-DotNetTool
Updates local tools for each project directory that has a local manifest in
its directory tree; otherwise updates global tools for that input directory.
.EXAMPLE
PS > Update-DotNetTool -AdditionalArgs '--verbosity', 'minimal'
Updates tools and passes additional dotnet update arguments through to each
update command.
.OUTPUTS
[PSCustomObject]
Returns an object with summary information:
- Scope : Local when a local tool manifest is found; otherwise Global
- WorkingDirectory : Directory used for manifest discovery and dotnet invocation
- ManifestPath : Local tool manifest path, or $null for global updates
- ToolsFound : Number of tools discovered before updating
- Updated : Number of tools updated successfully
- Skipped : Number of tools skipped by -WhatIf or -Confirm
- Failed : Number of tools that failed to update
- ExitCode : 0 when all updates succeeded; otherwise 1
- Results : Per-tool result objects with PackageId, Version, Status, and Message
When -ListOutdated is specified, returns one object per outdated tool with
Scope, PackageId, CurrentVersion, LatestVersion, WorkingDirectory, and ManifestPath.
.NOTES
- Requires dotnet CLI in PATH
- Local tool manifest discovery walks from -Path up to the filesystem root
- Auto scope uses global tools only when no local .config/dotnet-tools.json manifest is found
- Outdated checks use 'dotnet tool search' and fall back to NuGet flat-container metadata
- Respects -WhatIf and -Confirm through SupportsShouldProcess
Author: Jon LaBelle
License: MIT
Source: https://github.com/jonlabelle/pwsh-profile/blob/main/Functions/Developer/Update-DotNetTool.ps1
.LINK
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-tool-update
.LINK
https://learn.microsoft.com/en-us/dotnet/core/tools/local-tools-how-to-use
.LINK
https://github.com/jonlabelle/pwsh-profile/blob/main/Functions/Developer/Update-DotNetTool.ps1
#>
[CmdletBinding(SupportsShouldProcess)]
[OutputType([PSCustomObject])]
param(
[Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[String]$Path = (Get-Location).Path,
[Parameter()]
[ValidateSet('Auto', 'Local', 'Global')]
[String]$Scope = 'Auto',
[Parameter()]
[Switch]$ListOutdated,
[Parameter()]
[Switch]$Prerelease,
[Parameter()]
[Switch]$Interactive,
[Parameter()]
[Switch]$IgnoreFailedSources,
[Parameter()]
[Switch]$NoHttpCache,
[Parameter()]
[Switch]$DisableParallel,
[Parameter()]
[ValidateNotNullOrEmpty()]
[String]$Framework,
[Parameter()]
[ValidateNotNullOrEmpty()]
[String[]]$AdditionalArgs
)
begin
{
Write-Verbose 'Starting .NET tool update'
$dotnetCommand = Get-Command -Name 'dotnet' -ErrorAction SilentlyContinue
if (-not $dotnetCommand)
{
throw 'dotnet CLI is not installed or not available in PATH. Install the .NET SDK and try again.'
}
Write-Verbose "dotnet found at: $($dotnetCommand.Source)"
function Find-DotNetToolManifest
{
param(
[Parameter(Mandatory)]
[String]$StartPath
)
$directory = [System.IO.DirectoryInfo]::new($StartPath)
while ($directory)
{
$configPath = Join-Path -Path $directory.FullName -ChildPath '.config'
$manifestPath = Join-Path -Path $configPath -ChildPath 'dotnet-tools.json'
if (Test-Path -LiteralPath $manifestPath -PathType Leaf)
{
return $manifestPath
}
$directory = $directory.Parent
}
return $null
}
function ConvertFrom-DotNetToolJson
{
param(
[Parameter(Mandatory)]
[String[]]$Output
)
$jsonText = ($Output | ForEach-Object { "$_".Trim() } | Where-Object { $_ }) -join "`n"
if ([string]::IsNullOrWhiteSpace($jsonText))
{
return @()
}
$parsed = $jsonText | ConvertFrom-Json
if (-not $parsed.PSObject.Properties.Name.Contains('data') -or -not $parsed.data)
{
return @()
}
$tools = @()
foreach ($tool in @($parsed.data))
{
if (-not [string]::IsNullOrWhiteSpace($tool.packageId))
{
$tools += [PSCustomObject]@{
PackageId = [String]$tool.packageId
Version = [String]$tool.version
}
}
}
return $tools
}
function ConvertFrom-DotNetToolTable
{
param(
[Parameter(Mandatory)]
[String[]]$Output
)
$tools = @()
foreach ($line in $Output)
{
$trimmedLine = "$line".Trim()
if ([string]::IsNullOrWhiteSpace($trimmedLine))
{
continue
}
if ($trimmedLine -match '^(Package Id|[-]+)')
{
continue
}
$columns = $trimmedLine -split '\s{2,}'
if ($columns.Count -lt 2 -or [string]::IsNullOrWhiteSpace($columns[0]))
{
continue
}
$tools += [PSCustomObject]@{
PackageId = [String]$columns[0]
Version = [String]$columns[1]
}
}
return $tools
}
function ConvertFrom-DotNetToolSearchTable
{
param(
[Parameter(Mandatory)]
[String[]]$Output
)
$tools = @()
foreach ($line in $Output)
{
$trimmedLine = "$line".Trim()
if ([string]::IsNullOrWhiteSpace($trimmedLine))
{
continue
}
if ($trimmedLine -match '^(Package ID|[-]+)')
{
continue
}
$columns = $trimmedLine -split '\s{2,}'
if ($columns.Count -lt 2 -or [string]::IsNullOrWhiteSpace($columns[0]))
{
continue
}
$tools += [PSCustomObject]@{
PackageId = [String]$columns[0]
LatestVersion = [String]$columns[1]
}
}
return $tools
}
function Get-DotNetToolList
{
param(
[Parameter(Mandatory)]
[String]$DotNetCommandName,
[Parameter(Mandatory)]
[ValidateSet('Local', 'Global')]
[String]$Scope
)
if ($Scope -eq 'Local')
{
$scopeArgument = '--local'
}
else
{
$scopeArgument = '--global'
}
$listArgs = @('tool', 'list', $scopeArgument, '--format', 'json')
Write-Verbose "Listing .NET $($Scope.ToLowerInvariant()) tools: dotnet $($listArgs -join ' ')"
$listOutput = @(& $DotNetCommandName @listArgs 2>&1)
$listExitCode = $LASTEXITCODE
if ($listExitCode -eq 0)
{
try
{
return @(ConvertFrom-DotNetToolJson -Output $listOutput)
}
catch
{
Write-Verbose "Unable to parse JSON tool list output, falling back to table output: $($_.Exception.Message)"
}
}
else
{
Write-Verbose "JSON tool list failed with exit code $listExitCode, falling back to table output."
}
$fallbackListArgs = @('tool', 'list', $scopeArgument)
Write-Verbose "Listing .NET $($Scope.ToLowerInvariant()) tools: dotnet $($fallbackListArgs -join ' ')"
$fallbackOutput = @(& $DotNetCommandName @fallbackListArgs 2>&1)
$fallbackExitCode = $LASTEXITCODE
if ($fallbackExitCode -ne 0)
{
$message = ($fallbackOutput | Where-Object { $_ }) -join ' '
throw "Failed to list .NET $($Scope.ToLowerInvariant()) tools: $message"
}
return @(ConvertFrom-DotNetToolTable -Output $fallbackOutput)
}
function Get-DotNetToolLatestVersion
{
param(
[Parameter(Mandatory)]
[String]$DotNetCommandName,
[Parameter(Mandatory)]
[String]$PackageId,
[Parameter()]
[Switch]$IncludePrerelease
)
$searchFailureMessage = $null
$searchArgs = @('tool', 'search', $PackageId, '--take', '20')
if ($IncludePrerelease.IsPresent)
{
$searchArgs += '--prerelease'
}
Write-Verbose "Searching latest .NET tool version: dotnet $($searchArgs -join ' ')"
$searchOutput = @(& $DotNetCommandName @searchArgs 2>&1)
$searchExitCode = $LASTEXITCODE
if ($searchExitCode -ne 0)
{
$searchFailureMessage = ($searchOutput | Where-Object { $_ }) -join ' '
Write-Verbose "dotnet tool search failed for '$PackageId': $searchFailureMessage"
}
else
{
$searchResults = @(ConvertFrom-DotNetToolSearchTable -Output $searchOutput)
$exactMatch = $searchResults |
Where-Object { [String]::Equals($_.PackageId, $PackageId, [StringComparison]::OrdinalIgnoreCase) } |
Select-Object -First 1
if ($exactMatch)
{
return [String]$exactMatch.LatestVersion
}
Write-Verbose "No exact latest-version search result found for .NET tool '$PackageId'."
}
$packageIdForUrl = $PackageId.ToLowerInvariant()
$packageIndexUri = 'https://api.nuget.org/v3-flatcontainer/{0}/index.json' -f ([System.Uri]::EscapeDataString($packageIdForUrl))
$fallbackFailureMessage = $null
try
{
Write-Verbose "Searching NuGet flat-container latest .NET tool version: $packageIndexUri"
$packageIndex = Invoke-RestMethod -Uri $packageIndexUri -ErrorAction Stop
$versions = @($packageIndex.versions | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
if (-not $IncludePrerelease.IsPresent)
{
$versions = @($versions | Where-Object { $_ -notmatch '-' })
}
if ($versions.Count -gt 0)
{
return [String]$versions[-1]
}
Write-Verbose "NuGet flat-container metadata did not include usable versions for .NET tool '$PackageId'."
$fallbackFailureMessage = 'No usable versions were returned.'
}
catch
{
$fallbackFailureMessage = $_.Exception.Message
}
if ($searchFailureMessage)
{
Write-Warning "Failed to determine latest version for .NET tool '$PackageId'. dotnet tool search failed: $searchFailureMessage. NuGet metadata fallback failed: $fallbackFailureMessage"
}
else
{
Write-Warning "Failed to determine latest version for .NET tool '$PackageId'. NuGet metadata fallback failed: $fallbackFailureMessage"
}
return $null
}
function Format-DotNetToolUpdateResult
{
param(
[Parameter(Mandatory)]
[String]$PackageId,
[String]$Version,
[Parameter(Mandatory)]
[String]$Status,
[String]$Message
)
[PSCustomObject]@{
PackageId = $PackageId
Version = $Version
Status = $Status
Message = $Message
}
}
function Format-DotNetToolOutdatedResult
{
param(
[Parameter(Mandatory)]
[String]$Scope,
[Parameter(Mandatory)]
[String]$PackageId,
[Parameter(Mandatory)]
[String]$CurrentVersion,
[Parameter(Mandatory)]
[String]$LatestVersion,
[Parameter(Mandatory)]
[String]$WorkingDirectory,
[String]$ManifestPath
)
[PSCustomObject]@{
Scope = $Scope
PackageId = $PackageId
CurrentVersion = $CurrentVersion
LatestVersion = $LatestVersion
WorkingDirectory = $WorkingDirectory
ManifestPath = $ManifestPath
}
}
}
process
{
try
{
$resolvedPath = $PSCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
}
catch
{
Write-Error "Unable to resolve path '$Path': $($_.Exception.Message)"
return
}
if (-not (Test-Path -LiteralPath $resolvedPath -PathType Container))
{
Write-Error "Path not found or is not a directory: $resolvedPath"
return
}
$manifestPath = Find-DotNetToolManifest -StartPath $resolvedPath
if ($Scope -eq 'Auto')
{
if ($manifestPath)
{
$effectiveScope = 'Local'
Write-Verbose "Found local .NET tool manifest: $manifestPath"
}
else
{
$effectiveScope = 'Global'
Write-Verbose 'No local .NET tool manifest found; using global tool scope.'
}
}
elseif ($Scope -eq 'Local')
{
if (-not $manifestPath)
{
Write-Error "No local .NET tool manifest found from '$resolvedPath' or its parent directories."
return
}
$effectiveScope = 'Local'
Write-Verbose "Using requested local .NET tool scope with manifest: $manifestPath"
}
else
{
$effectiveScope = 'Global'
$manifestPath = $null
Write-Verbose 'Using requested global .NET tool scope.'
}
Push-Location -LiteralPath $resolvedPath
try
{
$tools = @(Get-DotNetToolList -DotNetCommandName $dotnetCommand.Name -Scope $effectiveScope)
}
finally
{
Pop-Location
}
$updatedCount = 0
$skippedCount = 0
$failedCount = 0
$results = @()
if ($tools.Count -eq 0)
{
Write-Verbose "No .NET $($effectiveScope.ToLowerInvariant()) tools found."
if ($ListOutdated.IsPresent)
{
Write-Host "No .NET $($effectiveScope.ToLowerInvariant()) tools found to check." -ForegroundColor Yellow
return
}
Write-Host "No .NET $($effectiveScope.ToLowerInvariant()) tools found to update." -ForegroundColor Yellow
return [PSCustomObject]@{
Scope = $effectiveScope
WorkingDirectory = $resolvedPath
ManifestPath = $manifestPath
ToolsFound = 0
Updated = 0
Skipped = 0
Failed = 0
ExitCode = 0
Results = @()
}
}
if ($ListOutdated.IsPresent)
{
$outdatedTools = @()
foreach ($tool in $tools)
{
$packageId = [String]$tool.PackageId
$currentVersion = [String]$tool.Version
$latestVersion = Get-DotNetToolLatestVersion -DotNetCommandName $dotnetCommand.Name -PackageId $packageId -IncludePrerelease:$Prerelease
if ([string]::IsNullOrWhiteSpace($latestVersion))
{
continue
}
if (-not [String]::Equals($currentVersion, $latestVersion, [StringComparison]::OrdinalIgnoreCase))
{
$outdatedTools += Format-DotNetToolOutdatedResult `
-Scope $effectiveScope `
-PackageId $packageId `
-CurrentVersion $currentVersion `
-LatestVersion $latestVersion `
-WorkingDirectory $resolvedPath `
-ManifestPath $manifestPath
}
}
if ($outdatedTools.Count -eq 0)
{
Write-Host "No outdated .NET $($effectiveScope.ToLowerInvariant()) tools found." -ForegroundColor Green
}
return $outdatedTools
}
foreach ($tool in $tools)
{
$packageId = [String]$tool.PackageId
$version = [String]$tool.Version
$updateArgs = @('tool', 'update', $packageId)
if ($effectiveScope -eq 'Local')
{
$updateArgs += '--local'
$updateArgs += '--tool-manifest'
$updateArgs += $manifestPath
}
else
{
$updateArgs += '--global'
}
if ($Prerelease.IsPresent)
{
$updateArgs += '--prerelease'
}
if ($Interactive.IsPresent)
{
$updateArgs += '--interactive'
}
if ($IgnoreFailedSources.IsPresent)
{
$updateArgs += '--ignore-failed-sources'
}
if ($NoHttpCache.IsPresent)
{
$updateArgs += '--no-http-cache'
}
if ($DisableParallel.IsPresent)
{
$updateArgs += '--disable-parallel'
}
if ($Framework)
{
$updateArgs += '--framework'
$updateArgs += $Framework
}
if ($AdditionalArgs)
{
$updateArgs += $AdditionalArgs
}
$target = "$effectiveScope .NET tool '$packageId'"
if (-not $PSCmdlet.ShouldProcess($target, 'Update'))
{
$skippedCount++
$results += Format-DotNetToolUpdateResult -PackageId $packageId -Version $version -Status 'Skipped' -Message 'Skipped by ShouldProcess'
continue
}
Write-Verbose "Updating .NET $($effectiveScope.ToLowerInvariant()) tool '$packageId': dotnet $($updateArgs -join ' ')"
Push-Location -LiteralPath $resolvedPath
try
{
$updateOutput = @(& $dotnetCommand.Name @updateArgs 2>&1)
$updateExitCode = $LASTEXITCODE
}
finally
{
Pop-Location
}
$message = ($updateOutput | Where-Object { $_ }) -join "`n"
if ($updateExitCode -eq 0)
{
$updatedCount++
$results += Format-DotNetToolUpdateResult -PackageId $packageId -Version $version -Status 'Success' -Message $message
}
else
{
$failedCount++
$results += Format-DotNetToolUpdateResult -PackageId $packageId -Version $version -Status 'Failed' -Message $message
Write-Warning "Failed to update .NET $($effectiveScope.ToLowerInvariant()) tool '$packageId': $message"
}
}
$exitCode = if ($failedCount -gt 0) { 1 } else { 0 }
if ($skippedCount -eq $tools.Count)
{
Write-Host "No .NET $($effectiveScope.ToLowerInvariant()) tools were updated; $skippedCount skipped." -ForegroundColor Yellow
}
elseif ($failedCount -eq 0)
{
Write-Host "Updated $updatedCount of $($tools.Count) .NET $($effectiveScope.ToLowerInvariant()) tool(s)." -ForegroundColor Green
}
elseif ($updatedCount -gt 0)
{
Write-Host "Updated $updatedCount of $($tools.Count) .NET $($effectiveScope.ToLowerInvariant()) tool(s); $failedCount failed." -ForegroundColor Yellow
}
else
{
Write-Host "No .NET $($effectiveScope.ToLowerInvariant()) tools were updated; $failedCount failed." -ForegroundColor Red
}
[PSCustomObject]@{
Scope = $effectiveScope
WorkingDirectory = $resolvedPath
ManifestPath = $manifestPath
ToolsFound = $tools.Count
Updated = $updatedCount
Skipped = $skippedCount
Failed = $failedCount
ExitCode = $exitCode
Results = $results
}
}
}