监控模块 优化
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
ThingHK Native AOT build script.
|
||||
.DESCRIPTION
|
||||
Builds ThingHK as Native AOT single-file executable and copies it to src-tauri/binaries/ for Tauri packaging.
|
||||
Usage: run .\build.ps1 in the ThingHK/ directory.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Configuration = "Release",
|
||||
[string]$Runtime = "win-x64"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Resolve script directory: try multiple methods for compatibility
|
||||
$scriptDir = $PSScriptRoot
|
||||
if (-not $scriptDir) {
|
||||
$cmd = $MyInvocation.MyCommand
|
||||
if ($cmd -and $cmd.Path) {
|
||||
$scriptDir = Split-Path -Parent $cmd.Path
|
||||
}
|
||||
}
|
||||
if (-not $scriptDir) {
|
||||
$scriptDir = (Get-Location).Path
|
||||
}
|
||||
|
||||
$projectPath = Join-Path $scriptDir "ThingHK.csproj"
|
||||
$publishDir = Join-Path $scriptDir "bin\$Configuration\net8.0-windows\$Runtime\publish"
|
||||
$destDir = Join-Path $scriptDir "..\src-tauri\binaries"
|
||||
$destPath = Join-Path $destDir "ThingHK.exe"
|
||||
|
||||
Write-Host "=== ThingHK Build Started ===" -ForegroundColor Cyan
|
||||
Write-Host "Config: $Configuration | Runtime: $Runtime"
|
||||
Write-Host "Project: $projectPath"
|
||||
Write-Host "ScriptDir: $scriptDir"
|
||||
|
||||
if (-not (Test-Path $projectPath)) {
|
||||
Write-Error "Project file not found: $projectPath"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 1. Clean old obj cache
|
||||
$objDir = Join-Path $scriptDir "obj"
|
||||
if (Test-Path $objDir) {
|
||||
Write-Host "`n[1/4] Cleaning obj cache..." -ForegroundColor Yellow
|
||||
Remove-Item $objDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# 2. dotnet publish (Native AOT)
|
||||
Write-Host "`n[2/4] Running dotnet publish (Native AOT)..." -ForegroundColor Yellow
|
||||
& dotnet publish $projectPath -c $Configuration -r $Runtime
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "dotnet publish failed (exit $LASTEXITCODE)"
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
$publishedExe = Join-Path $publishDir "ThingHK.exe"
|
||||
if (-not (Test-Path $publishedExe)) {
|
||||
Write-Error "Build output not found: $publishedExe"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 3. Ensure destination directory exists
|
||||
if (-not (Test-Path $destDir)) {
|
||||
Write-Host "`n[3/4] Creating destination: $destDir" -ForegroundColor Yellow
|
||||
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
|
||||
}
|
||||
|
||||
# 4. Copy to src-tauri/binaries/
|
||||
Write-Host "`n[4/4] Copying to $destPath" -ForegroundColor Yellow
|
||||
Copy-Item $publishedExe $destPath -Force
|
||||
|
||||
$destItem = Get-Item $destPath
|
||||
Write-Host "`n=== Build Complete ===" -ForegroundColor Green
|
||||
Write-Host ("Output: {0}" -f $destItem.FullName)
|
||||
Write-Host ("Size: {0:N2} MB" -f ($destItem.Length / 1MB))
|
||||
Write-Host ("Time: {0}" -f $destItem.LastWriteTime)
|
||||
Reference in New Issue
Block a user