-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
114 lines (97 loc) · 3.14 KB
/
Copy pathdeploy.ps1
File metadata and controls
114 lines (97 loc) · 3.14 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
<#
.SYNOPSIS
Builds and deploys Dayforce.LocalSdkResolver to MSBuild SdkResolvers folders.
.DESCRIPTION
Compiles the resolver in Release configuration, then copies the DLL and
an XML manifest to the SdkResolvers directories for both dotnet CLI and
Visual Studio (if installed). Requires an elevated (Administrator) shell.
.PARAMETER Uninstall
Remove Dayforce.LocalSdkResolver from all SdkResolvers directories instead of deploying.
#>
[CmdletBinding()]
param(
[switch]$Uninstall
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$resolverName = 'Dayforce.LocalSdkResolver'
$manifest = "<SdkResolver><Path>$resolverName.dll</Path></SdkResolver>"
# --- Collect target directories ---------------------------------------------------
$targets = @()
# dotnet CLI — deploy to ALL installed SDK versions
$dotnetCmd = Get-Command dotnet -ErrorAction SilentlyContinue
if ($dotnetCmd)
{
$dotnetRoot = Split-Path $dotnetCmd.Source # e.g. C:\Program Files\dotnet
$sdksDir = Join-Path $dotnetRoot 'sdk'
if (Test-Path $sdksDir)
{
foreach ($sdkDir in Get-ChildItem $sdksDir -Directory)
{
$resolversDir = Join-Path $sdkDir.FullName "SdkResolvers"
if (Test-Path $resolversDir)
{
$targets += Join-Path $resolversDir $resolverName
}
}
}
}
# Visual Studio (via vswhere)
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
if (Test-Path $vswhere)
{
$vsPath = & $vswhere -latest -property installationPath 2>$null
if ($vsPath)
{
$targets += Join-Path $vsPath "MSBuild\Current\Bin\SdkResolvers\$resolverName"
}
}
if ($targets.Count -eq 0)
{
Write-Error 'Could not find any dotnet SDK or Visual Studio installation.'
}
# --- Uninstall --------------------------------------------------------------------
if ($Uninstall)
{
foreach ($dir in $targets)
{
if (Test-Path $dir)
{
Remove-Item $dir -Recurse -Force
Write-Host "Removed: $dir" -ForegroundColor Yellow
}
else
{
Write-Host "Not found (skipped): $dir" -ForegroundColor DarkGray
}
}
Write-Host "`nUninstall complete." -ForegroundColor Green
return
}
# --- Build ------------------------------------------------------------------------
$scriptDir = $PSScriptRoot
Push-Location $scriptDir
try
{
Write-Host "Building $resolverName..." -ForegroundColor Cyan
& dotnet build -c Release
if ($LASTEXITCODE -ne 0) { Write-Error 'Build failed.' }
}
finally
{
Pop-Location
}
$dll = Join-Path $scriptDir "bin\Release\net9.0\$resolverName.dll"
if (-not (Test-Path $dll))
{
Write-Error "Build output not found: $dll"
}
# --- Deploy -----------------------------------------------------------------------
foreach ($dir in $targets)
{
New-Item $dir -ItemType Directory -Force | Out-Null
Copy-Item $dll $dir -Force
$manifest | Set-Content (Join-Path $dir "$resolverName.xml")
Write-Host "Deployed to: $dir" -ForegroundColor Green
}
Write-Host "`nDone. Set LOCAL_SDK_ROOTS to start resolving local SDKs." -ForegroundColor Green