初始化版本控制:TS660 DLL 源码、构建脚本与 SDK(Release) 产物
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
# build_debug_x64.ps1
|
||||
# 一键编译 TS660_DLL 解决方案 (Debug + x64)
|
||||
#
|
||||
# 用法:
|
||||
# 1. 右键此文件 -> "用 PowerShell 运行"
|
||||
# 2. 或在 PowerShell 中执行: .\build_debug_x64.ps1
|
||||
# 3. 或在 cmd 中执行: powershell -ExecutionPolicy Bypass -File build_debug_x64.ps1
|
||||
#
|
||||
# 如遇执行策略限制, 用以下命令临时绕过(仅当前会话有效):
|
||||
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
|
||||
|
||||
param(
|
||||
[string]$Configuration = "Debug",
|
||||
[string]$Platform = "x64"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# 切到脚本所在目录(项目根)
|
||||
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $scriptRoot
|
||||
Write-Host "[INFO] Working dir: $scriptRoot" -ForegroundColor Cyan
|
||||
|
||||
$solution = Join-Path $scriptRoot "TS660_DLL.sln"
|
||||
if (-not (Test-Path $solution)) {
|
||||
Write-Host "[ERROR] Solution file not found: $solution" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# === 自动定位 MSBuild ===
|
||||
$msbuild = $null
|
||||
|
||||
# 方式 1: PATH 中已有 msbuild
|
||||
$found = Get-Command msbuild -ErrorAction SilentlyContinue
|
||||
if ($found) {
|
||||
$msbuild = $found.Source
|
||||
Write-Host "[INFO] Found MSBuild in PATH." -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# 方式 2: 通过 vswhere 自动定位最新 VS 安装
|
||||
if (-not $msbuild) {
|
||||
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if (Test-Path $vswhere) {
|
||||
$vsPath = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath 2>$null
|
||||
if ($vsPath) {
|
||||
$candidate = Join-Path $vsPath "MSBuild\Current\Bin\MSBuild.exe"
|
||||
if (Test-Path $candidate) {
|
||||
$msbuild = $candidate
|
||||
Write-Host "[INFO] Found MSBuild via vswhere: $msbuild" -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 方式 3: 常见安装路径硬编码兜底
|
||||
if (-not $msbuild) {
|
||||
$candidates = @(
|
||||
"D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
|
||||
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
|
||||
"D:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe",
|
||||
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
|
||||
)
|
||||
foreach ($c in $candidates) {
|
||||
if (Test-Path $c) {
|
||||
$msbuild = $c
|
||||
Write-Host "[INFO] Found MSBuild at fallback path: $msbuild" -ForegroundColor Gray
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $msbuild) {
|
||||
Write-Host "[ERROR] MSBuild not found. Please install Visual Studio 2019/2022 with C++ workload." -ForegroundColor Red
|
||||
Write-Host " Or add MSBuild.exe to PATH manually." -ForegroundColor Yellow
|
||||
exit 2
|
||||
}
|
||||
|
||||
Write-Host "[INFO] MSBuild: $msbuild" -ForegroundColor Cyan
|
||||
Write-Host "[INFO] Configuration: $Configuration | Platform: $Platform" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# === 执行编译 ===
|
||||
$startTime = Get-Date
|
||||
& $msbuild $solution /t:Build /p:Configuration=$Configuration /p:Platform=$Platform /v:minimal /nologo
|
||||
$exitCode = $LASTEXITCODE
|
||||
$elapsed = (Get-Date) - $startTime
|
||||
|
||||
Write-Host ""
|
||||
if ($exitCode -eq 0) {
|
||||
Write-Host "[OK] Build succeeded in $($elapsed.TotalSeconds.ToString('0.00'))s" -ForegroundColor Green
|
||||
|
||||
# 显示产物
|
||||
$outDir = Join-Path $scriptRoot "$Platform\$Configuration"
|
||||
if (Test-Path $outDir) {
|
||||
Write-Host ""
|
||||
Write-Host "[INFO] Outputs in: $outDir" -ForegroundColor Cyan
|
||||
Get-ChildItem $outDir -File |
|
||||
Where-Object { $_.Extension -in '.dll', '.lib', '.exe' } |
|
||||
Sort-Object Name |
|
||||
ForEach-Object {
|
||||
$sizeKB = "{0,8:N1} KB" -f ($_.Length / 1KB)
|
||||
Write-Host (" {0,-20} {1}" -f $_.Name, $sizeKB)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-Host "[FAIL] Build failed with exit code $exitCode (took $($elapsed.TotalSeconds.ToString('0.00'))s)" -ForegroundColor Red
|
||||
}
|
||||
|
||||
exit $exitCode
|
||||
Reference in New Issue
Block a user