-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.ps1
More file actions
81 lines (67 loc) · 2.68 KB
/
Copy pathpack.ps1
File metadata and controls
81 lines (67 loc) · 2.68 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
Param(
[string]$OutDir = ".\dist",
[string]$Configuration = "Release",
[string]$Project = "src\LeXtudio.Windows\LeXtudio.Windows.csproj"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$RepoRoot = $PSScriptRoot
$ProjectPath = if ([System.IO.Path]::IsPathRooted($Project)) { $Project } else { Join-Path $RepoRoot $Project }
if (-not (Test-Path $ProjectPath)) {
throw "Project file not found: $ProjectPath"
}
$OutputPath = if ([System.IO.Path]::IsPathRooted($OutDir)) { $OutDir } else { Join-Path $RepoRoot $OutDir }
function Find-MSBuild {
$programFilesX86 = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)")
if ($programFilesX86) {
$vswhere = Join-Path $programFilesX86 "Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere) {
$installPath = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath 2>$null
if ($installPath) {
$candidate = Join-Path $installPath "MSBuild\Current\Bin\MSBuild.exe"
if (Test-Path $candidate) {
return (Resolve-Path $candidate).Path
}
}
}
}
$command = Get-Command msbuild -ErrorAction SilentlyContinue
if ($command) {
return $command.Path
}
throw "MSBuild was not found. Install Visual Studio/MSBuild to pack the Windows/WPF target."
}
function Resolve-ProjectPath([string]$Project) {
if (Test-Path $Project) {
return (Resolve-Path $Project).Path
}
$candidate = Join-Path $RepoRoot $Project
if (Test-Path $candidate) {
return (Resolve-Path $candidate).Path
}
throw "Project file not found: $Project"
}
function Reset-Directory([string]$Path) {
if (Test-Path $Path) {
Remove-Item -LiteralPath $Path -Recurse -Force
}
New-Item -ItemType Directory -Path $Path | Out-Null
}
Reset-Directory $OutputPath
$msbuild = Find-MSBuild
Write-Host "MSBuild: $msbuild"
Write-Host "Packing project: $ProjectPath"
Write-Host "Configuration: $Configuration"
Write-Host "Output path: $OutputPath"
$previousOutDir = [Environment]::GetEnvironmentVariable("OutDir", "Process")
[Environment]::SetEnvironmentVariable("OutDir", $null, "Process")
try {
& $msbuild $ProjectPath /restore /t:Pack /p:Configuration=$Configuration /p:PackageOutputPath=$OutputPath /v:minimal /nologo
if ($LASTEXITCODE -ne 0) {
throw "MSBuild pack failed with exit code $LASTEXITCODE"
}
} finally {
[Environment]::SetEnvironmentVariable("OutDir", $previousOutDir, "Process")
}
Write-Host "Package created in: $OutputPath"
Get-ChildItem -Path $OutputPath -File | ForEach-Object { Write-Host " $($_.Name)" }