feat(CI): 添加 NuGet 安装脚本并优化 CI 流程
添加三个 NuGet 安装脚本(批处理和 PowerShell),支持直接下载和通过 Chocolatey 安装 修改 CI 工作流,优先使用 Chocolatey 安装 NuGet 并更新 PATH 路径
This commit is contained in:
parent
8cc88be5f6
commit
610eb4f20d
@ -238,26 +238,27 @@ jobs:
|
|||||||
$nugetPath = Get-Command nuget -ErrorAction SilentlyContinue
|
$nugetPath = Get-Command nuget -ErrorAction SilentlyContinue
|
||||||
if ($nugetPath) {
|
if ($nugetPath) {
|
||||||
Write-Host "NuGet already installed: $($nugetPath.Source)"
|
Write-Host "NuGet already installed: $($nugetPath.Source)"
|
||||||
|
$nugetVersion = nuget help | Select-String -Pattern "NuGet Version" | Select-Object -First 1
|
||||||
|
Write-Host "NuGet version: $nugetVersion"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download NuGet CLI
|
# Use Chocolatey to install NuGet (proven to work)
|
||||||
Write-Host "Downloading NuGet CLI..."
|
Write-Host "Installing NuGet via Chocolatey..."
|
||||||
try {
|
choco install nuget.commandline -y
|
||||||
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\nuget.exe" -TimeoutSec 120
|
|
||||||
} catch {
|
|
||||||
Write-Host "Download failed, trying alternative..."
|
|
||||||
# Try alternative download
|
|
||||||
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/v6.7.0/nuget.exe" -OutFile "C:\nuget.exe" -TimeoutSec 120
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add to PATH
|
# Update PATH to include Chocolatey
|
||||||
$env:PATH = "C:\;$env:PATH"
|
$env:PATH = "C:\ProgramData\chocolatey\bin;$env:PATH"
|
||||||
Add-Content -Path $env:GITHUB_PATH -Value "C:\"
|
Add-Content -Path $env:GITHUB_PATH -Value "C:\ProgramData\chocolatey\bin"
|
||||||
|
|
||||||
# Verify installation
|
# Verify installation
|
||||||
$nugetVersion = C:\nuget.exe help | Select-String -Pattern "NuGet Version" | Select-Object -First 1
|
if (Get-Command nuget -ErrorAction SilentlyContinue) {
|
||||||
Write-Host "NuGet installed: $nugetVersion"
|
Write-Host "NuGet installed successfully via Chocolatey"
|
||||||
|
$nugetVersion = nuget help | Select-String -Pattern "NuGet Version" | Select-Object -First 1
|
||||||
|
Write-Host "NuGet version: $nugetVersion"
|
||||||
|
} else {
|
||||||
|
Write-Host "WARNING: NuGet installation may have failed, but continuing..."
|
||||||
|
}
|
||||||
|
|
||||||
- name: Fix long paths
|
- name: Fix long paths
|
||||||
shell: powershell
|
shell: powershell
|
||||||
@ -293,13 +294,13 @@ jobs:
|
|||||||
- name: Build Windows Debug
|
- name: Build Windows Debug
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
$env:PATH = "C:\flutter\bin;C:\;$env:PATH"
|
$env:PATH = "C:\flutter\bin;C:\ProgramData\chocolatey\bin;$env:PATH"
|
||||||
flutter build windows
|
flutter build windows
|
||||||
|
|
||||||
- name: Build Windows Release
|
- name: Build Windows Release
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
$env:PATH = "C:\flutter\bin;C:\;$env:PATH"
|
$env:PATH = "C:\flutter\bin;C:\ProgramData\chocolatey\bin;$env:PATH"
|
||||||
flutter build windows --release
|
flutter build windows --release
|
||||||
|
|
||||||
- name: Upload Debug build artifacts
|
- name: Upload Debug build artifacts
|
||||||
|
|||||||
35
fix_nuget_choco.bat
Normal file
35
fix_nuget_choco.bat
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
@echo off
|
||||||
|
REM Fix NuGet installation using Chocolatey
|
||||||
|
|
||||||
|
echo Installing NuGet via Chocolatey...
|
||||||
|
|
||||||
|
REM Check if Chocolatey is available
|
||||||
|
where choco >nul 2>nul
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Chocolatey not found, installing Chocolatey first...
|
||||||
|
powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Installing NuGet via Chocolatey...
|
||||||
|
choco install nuget.commandline -y
|
||||||
|
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo SUCCESS: NuGet installed via Chocolatey
|
||||||
|
echo Updating PATH...
|
||||||
|
set PATH=C:\ProgramData\chocolatey\bin;%PATH%
|
||||||
|
setx PATH "C:\ProgramData\chocolatey\bin;%PATH%"
|
||||||
|
|
||||||
|
echo Verifying installation...
|
||||||
|
nuget help | findstr "NuGet"
|
||||||
|
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo NuGet is working correctly!
|
||||||
|
) else (
|
||||||
|
echo WARNING: NuGet installed but not accessible
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
echo ERROR: NuGet installation failed
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
pause
|
||||||
67
fix_nuget_ssl.ps1
Normal file
67
fix_nuget_ssl.ps1
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# NuGet 安装脚本 - 解决 SSL 问题
|
||||||
|
Write-Host "=== 安装 NuGet ===" -ForegroundColor Green
|
||||||
|
|
||||||
|
# 设置 TLS 1.2
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
|
# 检查是否已安装
|
||||||
|
$nugetExists = Get-Command nuget -ErrorAction SilentlyContinue
|
||||||
|
if ($nugetExists) {
|
||||||
|
Write-Host "NuGet 已安装: $($nugetExists.Source)" -ForegroundColor Green
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# 下载 NuGet
|
||||||
|
Write-Host "下载 NuGet CLI..." -ForegroundColor Yellow
|
||||||
|
$downloadUrls = @(
|
||||||
|
"https://dist.nuget.org/win-x86-commandline/latest/nuget.exe",
|
||||||
|
"https://dist.nuget.org/win-x86-commandline/v6.7.0/nuget.exe",
|
||||||
|
"http://dist.nuget.org/win-x86-commandline/v6.7.0/nuget.exe"
|
||||||
|
)
|
||||||
|
|
||||||
|
$downloaded = $false
|
||||||
|
foreach ($url in $downloadUrls) {
|
||||||
|
try {
|
||||||
|
Write-Host "尝试下载: $url"
|
||||||
|
$webClient = New-Object System.Net.WebClient
|
||||||
|
$webClient.DownloadFile($url, "C:\nuget.exe")
|
||||||
|
$downloaded = $true
|
||||||
|
Write-Host "下载成功!" -ForegroundColor Green
|
||||||
|
break
|
||||||
|
} catch {
|
||||||
|
Write-Host "下载失败: $($_.Exception.Message)" -ForegroundColor Red
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $downloaded) {
|
||||||
|
Write-Host "所有下载都失败了,尝试使用 Chocolatey..." -ForegroundColor Yellow
|
||||||
|
try {
|
||||||
|
choco install nuget.commandline -y
|
||||||
|
if (Get-Command nuget -ErrorAction SilentlyContinue) {
|
||||||
|
Write-Host "通过 Chocolatey 安装成功!" -ForegroundColor Green
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host "Chocolatey 安装也失败了: $($_.Exception.Message)" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "NuGet 安装失败,但继续构建..." -ForegroundColor Yellow
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# 验证安装
|
||||||
|
if (Test-Path "C:\nuget.exe") {
|
||||||
|
$env:PATH = "C:\;$env:PATH"
|
||||||
|
Write-Host "NuGet 安装完成" -ForegroundColor Green
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
try {
|
||||||
|
$version = & "C:\nuget.exe" help | Select-String -Pattern "NuGet Version" | Select-Object -First 1
|
||||||
|
Write-Host "版本信息: $version" -ForegroundColor Green
|
||||||
|
} catch {
|
||||||
|
Write-Host "NuGet 可用,但版本检查失败" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "NuGet 文件不存在" -ForegroundColor Red
|
||||||
|
}
|
||||||
39
install_nuget_simple.bat
Normal file
39
install_nuget_simple.bat
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
@echo off
|
||||||
|
REM Simple NuGet installer for Windows
|
||||||
|
|
||||||
|
echo Installing NuGet...
|
||||||
|
|
||||||
|
REM Check if NuGet exists
|
||||||
|
where nuget >nul 2>nul
|
||||||
|
if %errorlevel% == 0 (
|
||||||
|
echo NuGet already installed
|
||||||
|
nuget help | findstr "NuGet"
|
||||||
|
pause
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Download NuGet using PowerShell
|
||||||
|
echo Downloading NuGet CLI...
|
||||||
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('http://dist.nuget.org/win-x86-commandline/v6.7.0/nuget.exe', 'C:\nuget.exe')"
|
||||||
|
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Download failed, trying alternative...
|
||||||
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://dist.nuget.org/win-x86-commandline/v6.7.0/nuget.exe', 'C:\nuget.exe')"
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Add to PATH
|
||||||
|
set PATH=C:\;%PATH%
|
||||||
|
setx PATH "C:\;%PATH%"
|
||||||
|
|
||||||
|
REM Verify installation
|
||||||
|
echo Verifying NuGet installation...
|
||||||
|
C:\nuget.exe help | findstr "NuGet"
|
||||||
|
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo SUCCESS: NuGet installed successfully
|
||||||
|
) else (
|
||||||
|
echo ERROR: NuGet installation failed
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
pause
|
||||||
Loading…
x
Reference in New Issue
Block a user