64 lines
2.1 KiB
PowerShell
64 lines
2.1 KiB
PowerShell
# Windows 构建修复脚本
|
|
# 以管理员身份运行
|
|
|
|
Write-Host "=== Windows Flutter 构建修复 ===" -ForegroundColor Green
|
|
|
|
# 1. 安装 NuGet
|
|
Write-Host "`n1. 安装 NuGet..." -ForegroundColor Yellow
|
|
$nugetPath = "C:\nuget.exe"
|
|
if (-not (Test-Path $nugetPath)) {
|
|
try {
|
|
Write-Host "下载 NuGet..."
|
|
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nugetPath
|
|
$env:PATH = "C:\;$env:PATH"
|
|
Write-Host "NuGet 安装成功" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "NuGet 下载失败: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
} else {
|
|
Write-Host "NuGet 已存在" -ForegroundColor Green
|
|
}
|
|
|
|
# 2. 启用长路径支持
|
|
Write-Host "`n2. 启用长路径支持..." -ForegroundColor Yellow
|
|
try {
|
|
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Type DWORD -Force
|
|
Write-Host "长路径支持已启用" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "长路径设置失败: $_" -ForegroundColor Red
|
|
}
|
|
|
|
# 3. 清理构建缓存
|
|
Write-Host "`n3. 清理构建缓存..." -ForegroundColor Yellow
|
|
if (Test-Path "build") {
|
|
Remove-Item -Path "build" -Recurse -Force
|
|
Write-Host "Build 目录已清理" -ForegroundColor Green
|
|
}
|
|
|
|
if (Test-Path "windows") {
|
|
Remove-Item -Path "windows" -Recurse -Force
|
|
Write-Host "Windows 目录已清理" -ForegroundColor Green
|
|
}
|
|
|
|
# 4. 重新创建 Windows 项目
|
|
Write-Host "`n4. 重新创建 Windows 项目..." -ForegroundColor Yellow
|
|
flutter create --platforms=windows .
|
|
|
|
# 5. 获取依赖
|
|
Write-Host "`n5. 获取依赖..." -ForegroundColor Yellow
|
|
flutter pub get
|
|
|
|
# 6. 构建 Debug 版本
|
|
Write-Host "`n6. 构建 Debug 版本..." -ForegroundColor Yellow
|
|
flutter build windows
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "`n=== 构建成功! ===" -ForegroundColor Green
|
|
Write-Host "输出目录: build\windows\runner\Debug\" -ForegroundColor Cyan
|
|
} else {
|
|
Write-Host "`n=== 构建失败 ===" -ForegroundColor Red
|
|
Write-Host "请检查错误信息并尝试手动修复" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host "`n修复完成!" -ForegroundColor Green |