Files
Hua.Todo/start-maui.ps1
T
ShaoHua 758f6772c6 1.更换软件协议为AGPL
2.切换项目名称为Hua.Todo
2026-04-06 22:06:30 +08:00

97 lines
3.3 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
param(
[switch]$Force = $false,
[string]$Framework = "net10.0-windows10.0.19041.0",
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",
[switch]$SkipWebBuild = $false
)
$ErrorActionPreference = "Stop"
Write-Host "====================================" -ForegroundColor Cyan
Write-Host " Hua.Todo.Maui 启动脚本" -ForegroundColor Cyan
Write-Host "====================================" -ForegroundColor Cyan
Write-Host ""
$mauiProjectPath = Join-Path $PSScriptRoot "src\Hua.Todo.Maui"
$mauiProjectFile = Join-Path $mauiProjectPath "Hua.Todo.Maui.csproj"
if (!(Test-Path $mauiProjectFile)) {
Write-Host "❌ MAUI 项目文件不存在: $mauiProjectFile" -ForegroundColor Red
exit 1
}
if (!(Get-Command "dotnet" -ErrorAction SilentlyContinue)) {
Write-Host "❌ 未找到 dotnet,请先安装 .NET SDK" -ForegroundColor Red
exit 1
}
Write-Host "[1/2] 检查 Hua.Todo.Maui 是否已在运行..." -ForegroundColor Yellow
$runningProcesses = Get-CimInstance Win32_Process -Filter "Name='Hua.Todo.Maui.exe' OR Name='dotnet.exe'" | Where-Object {
$_.CommandLine -like "*Hua.Todo.Maui*"
}
if ($runningProcesses) {
$pids = ($runningProcesses.ProcessId | Sort-Object) -join ", "
Write-Host "⚠️ Hua.Todo.Maui 可能已在运行中" -ForegroundColor Yellow
Write-Host " 进程 ID: ($pids)" -ForegroundColor Gray
if ($Force) {
Write-Host ""
Write-Host "🔄 强制关闭并重新启动..." -ForegroundColor Yellow
try {
$runningProcesses | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction Stop }
Write-Host "✅ 旧进程已停止" -ForegroundColor Green
Start-Sleep -Seconds 1
} catch {
Write-Host "❌ 停止进程失败: $_" -ForegroundColor Red
exit 1
}
} else {
Write-Host " 如果需要重新启动,请使用 -Force 参数" -ForegroundColor Gray
Write-Host ""
exit 0
}
} else {
Write-Host "✓ Hua.Todo.Maui 未运行" -ForegroundColor Green
Write-Host ""
}
Write-Host "[2/2] 启动 Hua.Todo.Maui..." -ForegroundColor Yellow
$argumentList = @(
"build",
$mauiProjectFile,
"-t:Run",
"-c", $Configuration,
"-f", $Framework
)
if ($SkipWebBuild) {
$argumentList += "-p:SkipWebBuild=true"
}
Write-Host "📂 工作目录: $mauiProjectPath" -ForegroundColor Gray
Write-Host "🧩 Framework: $Framework" -ForegroundColor Gray
Write-Host "⚙️ Configuration: $Configuration" -ForegroundColor Gray
Write-Host "🚀 启动应用..." -ForegroundColor Green
Write-Host ""
try {
$mauiProcess = Start-Process -FilePath "dotnet" -ArgumentList $argumentList -WorkingDirectory $mauiProjectPath -PassThru
Write-Host "✅ Hua.Todo.Maui 已启动" -ForegroundColor Green
Write-Host " 进程 ID: ($($mauiProcess.Id))" -ForegroundColor Gray
Write-Host ""
Write-Host "📝 提示:" -ForegroundColor Yellow
Write-Host " - 使用 -Force 参数可以强制重启" -ForegroundColor Gray
Write-Host " - 使用 -SkipWebBuild 可跳过内置 Web 资源构建" -ForegroundColor Gray
Write-Host " - 使用 -Framework 可指定目标框架(如 net10.0-windows10.0.19041.0" -ForegroundColor Gray
Write-Host ""
} catch {
Write-Host "❌ 启动失败: $_" -ForegroundColor Red
exit 1
}