-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuild-Debug.ps1
More file actions
155 lines (131 loc) · 6.58 KB
/
Build-Debug.ps1
File metadata and controls
155 lines (131 loc) · 6.58 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
# 编译 Debug 版本
# PowerShell 脚本
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "Continue"
Write-Host ("─" * 75) -ForegroundColor Cyan
Write-Host " 构建 YTPlayer - Debug 版本" -ForegroundColor Cyan
Write-Host ("─" * 75) -ForegroundColor Cyan
Write-Host ""
Write-Host "正在查找 MSBuild..." -ForegroundColor Yellow
# 方法 1: 使用 vswhere.exe(推荐)
$msbuildPath = $null
$vsWhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vsWhere) {
$msbuildPath = & $vsWhere `
-latest `
-requires Microsoft.Component.MSBuild `
-find "MSBuild\**\Bin\MSBuild.exe" `
-prerelease 2>$null | Select-Object -First 1
}
# 方法 2: 手动搜索常见路径(备用方案)
if (-not $msbuildPath) {
Write-Host "vswhere.exe 未找到,尝试常见安装路径..." -ForegroundColor Yellow
$searchPaths = @(
# E: 可能的 VS 2022 安装路径
"E:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe",
"E:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe",
"E:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe",
"E:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe",
# D: 盘
"D:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe",
"D:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe",
"D:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe",
"D:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe",
# C: 默认安装路径
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe",
# VS 2019
"E:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
"D:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe"
)
foreach ($path in $searchPaths) {
if (Test-Path $path) {
$msbuildPath = $path
Write-Host " 找到自定义路径的 MSBuild" -ForegroundColor Green
break
}
}
}
if (-not $msbuildPath) {
Write-Host ""
Write-Host "× 错误: 未找到 MSBuild" -ForegroundColor Red
Write-Host ""
Write-Host "请先安装 Visual Studio Build Tools:" -ForegroundColor Yellow
Write-Host " powershell -ExecutionPolicy Bypass -File .\install_build_tools.ps1" -ForegroundColor White
Write-Host ""
Write-Host "或访问: https://visualstudio.microsoft.com/downloads/" -ForegroundColor Yellow
Write-Host "选择 “Build Tools for Visual Studio 2022”" -ForegroundColor Yellow
exit 1
}
Write-Host "✓ 找到 MSBuild: $msbuildPath" -ForegroundColor Green
# 读取 MSBuild 版本
try {
$version = & $msbuildPath -version 2>&1 | Select-String "(\d+\.\d+\.\d+)" | ForEach-Object { $_.Matches[0].Value }
if ($version) {
Write-Host " 版本: $version" -ForegroundColor Gray
}
} catch {
Write-Host " (无法读取版本)" -ForegroundColor Gray
}
Write-Host ""
# 解决方案文件
$solutionFile = "YTPlayer.sln"
# 还原 NuGet 包(统一 x64)
Write-Host "[1/2] 还原 NuGet 包..." -ForegroundColor Yellow
& $msbuildPath /t:Restore $solutionFile /p:Configuration=Debug /p:Platform="x64" /v:minimal /nologo
if ($LASTEXITCODE -ne 0) {
Write-Host " × NuGet 包还原失败" -ForegroundColor Red
exit 1
}
Write-Host " ✓ NuGet 包还原成功" -ForegroundColor Green
Write-Host ""
# 构建项目(Debug 配置)
Write-Host "[2/2] 开始编译项目 (Debug 配置, x64)..." -ForegroundColor Yellow
Write-Host ""
$startTime = Get-Date
& $msbuildPath $solutionFile /p:Configuration=Debug /p:Platform="x64" /t:Rebuild /v:minimal /nologo /m
$exitCode = $LASTEXITCODE
$elapsed = (Get-Date) - $startTime
Write-Host ""
Write-Host ("─" * 75) -ForegroundColor Cyan
if ($exitCode -eq 0) {
Write-Host " ✓ 编译成功" -ForegroundColor Green
Write-Host ("─" * 75) -ForegroundColor Cyan
Write-Host ""
Write-Host "耗时: $($elapsed.TotalSeconds.ToString('0.0')) 秒" -ForegroundColor Gray
Write-Host ""
Write-Host "输出文件:" -ForegroundColor Yellow
if (Test-Path "bin\Debug\YTPlayer.exe") {
$fileInfo = Get-Item "bin\Debug\YTPlayer.exe"
Write-Host " ✓ bin\Debug\YTPlayer.exe (启动器)" -ForegroundColor Green
Write-Host " 大小: $([math]::Round($fileInfo.Length / 1KB, 1)) KB" -ForegroundColor Gray
Write-Host " 修改时间: $($fileInfo.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss'))" -ForegroundColor Gray
}
if (Test-Path "bin\Debug\YTPlayer.Updater.exe") {
$fileInfo = Get-Item "bin\Debug\YTPlayer.Updater.exe"
Write-Host " ✓ bin\Debug\YTPlayer.Updater.exe" -ForegroundColor Green
Write-Host " 大小: $([math]::Round($fileInfo.Length / 1KB, 1)) KB" -ForegroundColor Gray
Write-Host " 修改时间: $($fileInfo.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss'))" -ForegroundColor Gray
}
Write-Host ""
Write-Host "运行程序:" -ForegroundColor Yellow
Write-Host " .\bin\Debug\YTPlayer.exe" -ForegroundColor White
Write-Host ""
Write-Host "调试日志位置:" -ForegroundColor Yellow
Write-Host " bin\Debug\Logs\Debug_YYYYMMDD_HHMMSS.log" -ForegroundColor Gray
Write-Host ""
} else {
Write-Host " × 编译失败 (退出代码: $exitCode)" -ForegroundColor Red
Write-Host ("─" * 75) -ForegroundColor Cyan
Write-Host ""
Write-Host "请向上查看详细错误信息。" -ForegroundColor Yellow
Write-Host ""
exit 1
}