1
1
# !/bin/env pwsh
2
2
3
+ # Requires -Version 7.0
4
+ # Requires -PSEdition Core
5
+
3
6
param (
4
7
[string ]$FileName = ' Azure.Sdk.Tools.Cli' ,
5
8
[string ]$Package = ' azsdk' ,
@@ -9,21 +12,13 @@ param(
9
12
[string ]$RunDirectory = (Resolve-Path (Join-Path $PSScriptRoot .. .. ..)),
10
13
[switch ]$Run ,
11
14
[switch ]$UpdateVsCodeConfig ,
12
- [switch ]$Clean
15
+ [switch ]$UpdatePathInProfile
13
16
)
14
17
15
18
$ErrorActionPreference = " Stop"
16
-
17
- if (-not $InstallDirectory )
18
- {
19
- $homeDir = if ($env: HOME ) { $env: HOME } else { $env: USERPROFILE }
20
- $InstallDirectory = (Join-Path $homeDir " .azure-sdk-mcp" " azsdk" )
21
- }
22
19
. (Join-Path $PSScriptRoot ' ..' ' scripts' ' Helpers' ' AzSdkTool-Helpers.ps1' )
23
20
24
- if ($Clean ) {
25
- Clear-Directory - Path $InstallDirectory
26
- }
21
+ $toolInstallDirectory = $InstallDirectory ? $InstallDirectory : (Get-CommonInstallDirectory )
27
22
28
23
if ($UpdateVsCodeConfig ) {
29
24
$vscodeConfigPath = Join-Path $PSScriptRoot " .." " .." " .." " .vscode" " mcp.json"
@@ -54,13 +49,30 @@ if ($UpdateVsCodeConfig) {
54
49
$vscodeConfig | ConvertTo-Json - Depth 10 | Set-Content - Path $vscodeConfigPath - Force
55
50
}
56
51
57
- $exe = Install-Standalone - Tool `
52
+ # Install to a temp directory first so we don't dump out all the other
53
+ # release zip contents to one of the users bin directories.
54
+ $tmp = $env: TEMP ? $env: TEMP : [System.IO.Path ]::GetTempPath()
55
+ $guid = [System.Guid ]::NewGuid()
56
+ $tempInstallDirectory = Join-Path $tmp " azsdk-install-$ ( $guid ) "
57
+ $tempExe = Install-Standalone - Tool `
58
58
- Version $Version `
59
59
- FileName $FileName `
60
60
- Package $Package `
61
- - Directory $InstallDirectory `
61
+ - Directory $tempInstallDirectory `
62
62
- Repository $Repository
63
63
64
+ Copy-Item - Path $tempExe - Destination $toolInstallDirectory - Force
65
+ $exeName = Split-Path $tempExe - Leaf
66
+ $exe = Join-Path $toolInstallDirectory $exeName
67
+
68
+ Write-Host " Package $package is installed at $exe "
69
+ if (! $UpdatePathInProfile ) {
70
+ Write-Warning " To add the tool to PATH for new shell sessions, re-run with -UpdatePathInProfile to modify the shell profile file."
71
+ } else {
72
+ Add-InstallDirectoryToPathInProfile - InstallDirectory $toolInstallDirectory
73
+ Write-Warning " '$exeName ' will be available in PATH for new shell sessions."
74
+ }
75
+
64
76
if ($Run ) {
65
77
Start-Process - WorkingDirectory $RunDirectory - FilePath $exe - ArgumentList ' start' - NoNewWindow - Wait
66
78
}
0 commit comments