1 Star 0 Fork 1

My_Component/NETworkManager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
build (deprecated).ps1 6.23 KB
一键复制 编辑 原始数据 按行查看 历史
BornToBeRoot 提交于 2024-04-27 07:53 +08:00 . CI: Add signing via SignPath
$ErrorActionPreference = "Stop"
# Set current directory to script directory
Set-Location -Path $PSScriptRoot
# Output path where the build and all generated files is stored
$BuildPath = "$PSScriptRoot\Build"
# Target framework and runtime identifier
$TargetFramework = "net8.0-windows10.0.17763.0"
$RuntimeIdentifier = "win-x64"
$TargetPlatform = "x64"
# Init git submodules
Start-Process -FilePath "git" -ArgumentList "submodule update --init" -Wait -NoNewWindow
# Remove old build and generated files
if (Test-Path -Path $BuildPath) {
Remove-Item -Path $BuildPath -Recurse -Force -ErrorAction Stop
}
# Run a cleanup before the build
& ".\cleanup.ps1"
# Update the version based on the current date (e.g. 2021.2.15.0)
$Date = Get-Date
$Patch = 0
$VersionString = "$($Date.Year).$($Date.Month).$($Date.Day).$Patch"
# Update assembly version
$PatternVersion = '\[assembly: AssemblyVersion\("(.*)"\)\]'
$PatternFileVersion = '\[assembly: AssemblyFileVersion\("(.*)"\)\]'
$AssemblyFile = "$PSScriptRoot\Source\GlobalAssemblyInfo.cs"
$AssemlbyContent = Get-Content -Path $AssemblyFile -Encoding utf8
$AssemlbyContent = $AssemlbyContent -replace $PatternVersion, "[assembly: AssemblyVersion(""$($VersionString)"")]"
$AssemlbyContent = $AssemlbyContent -replace $PatternFileVersion, "[assembly: AssemblyFileVersion(""$($VersionString)"")]"
$AssemlbyContent | Set-Content -Path $AssemblyFile -Encoding utf8
# Update inno setup version
$PatternSetupVersion = '#define MyAppVersion "(.*)"'
$InnoSetupFile = "$PSScriptRoot\InnoSetup.iss"
$SetupContent = Get-Content -Path $InnoSetupFile -Encoding utf8
$SetupContent = $SetupContent -replace $PatternSetupVersion, "#define MyAppVersion ""$($VersionString)"""
$SetupContent | Set-Content -Path $InnoSetupFile -Encoding utf8
### Warnings ###
# CS4014 - Call is not awaited
# NU1701 - Target framework is .NET Framework
# CS1591 - Missing XML comment
# Try to get msbuild path with vswhere (See: https://www.meziantou.net/locating-msbuild-on-a-machine.htm)
$VSwherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not(Test-Path -Path $VSwherePath -PathType Leaf)) {
Write-Error -Message "Could not find VSwhere. Is Visual Studio installed?" -ErrorAction Stop
}
$VSwhere = & $VSwherePath -version "[16.0,18.0)" -products * -requires Microsoft.Component.MSBuild -prerelease -latest -utf8 -format json | ConvertFrom-Json
$MSBuildPath = [System.IO.Path]::Combine($VSwhere[0].installationPath, "MSBuild", "Current", "Bin", "MSBuild.exe")
# Test if we found msbuild
if (-not(Test-Path -Path $MSBuildPath -PathType Leaf)) {
Write-Error -Message "Could not find msbuild. Is Visual Studio installed?" -ErrorAction Stop
}
# Build with msbuild
Start-Process -FilePath $MSBuildPath -ArgumentList "$PSScriptRoot\Source\NETworkManager.sln /restore /t:Clean,Build /p:Configuration=Release /p:TargetFramework=$TargetFramework /p:RuntimeIdentifier=$RuntimeIdentifier /p:Platform=$TargetPlatform /p:WarningLevel=0" -RedirectStandardOutput .\log.txt -RedirectStandardError .\log_err.txt -Wait -NoNewWindow
Get-Content .\log.txt
Get-Content .\log_err.txt
# Test if build is available
if (-not(Test-Path -Path "$PSScriptRoot\Source\NETworkManager\bin\Release\$TargetFramework\$RuntimeIdentifier\NETworkManager.exe" -PathType Leaf)) {
Write-Error -Message "Could not find release build. Is .NET SDK 8.0 or later installed? Check logs above for more information." -ErrorAction Stop
}
else {
Write-Host -Object "`nBuild successful!" -ForegroundColor Green
}
# Create folder
New-Item -Path "$BuildPath\NETworkManager" -ItemType Directory -Force
# Copy files
Copy-Item -Path "$PSScriptRoot\Source\NETworkManager\bin\Release\$TargetFramework\$RuntimeIdentifier\*" -Destination "$BuildPath\NETworkManager" -Recurse -Force
# Get NETworkManager file version
$Version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$BuildPath\NETworkManager\NETworkManager.exe").FileVersion
# Remove .pdb files
Get-ChildItem -Path "$BuildPath\NETworkManager" | Where-Object { $_.Name.EndsWith(".pdb") } | Remove-Item
# Cleanup some other files
Remove-Item -Path "$BuildPath\NETworkManager\WebView2Loader.dll"
# Create archive
Compress-Archive -Path "$BuildPath\NETworkManager" -DestinationPath "$BuildPath\NETworkManager_$($Version)_Archive.zip"
# Create portable archive
New-Item -Path "$BuildPath\NETworkManager" -Name "IsPortable.settings" -ItemType File
Compress-Archive -Path "$BuildPath\NETworkManager" -DestinationPath "$BuildPath\NETworkManager_$($Version)_Portable.zip"
Remove-Item -Path "$BuildPath\NETworkManager\IsPortable.settings"
# Create installer with InnoSetup
$InnoSetupPath = "${env:ProgramFiles(x86)}\Inno Setup 6"
# Check if additional language files are available for InnoSetup
$InnoSetupLanguageMissing = $false
foreach ($File in @("ChineseSimplified.isl", "ChineseTraditional.isl", "Hungarian.isl", "Korean.isl")) {
if (-not(Test-Path -Path "$InnoSetupPath\Languages\$File" -PathType Leaf)) {
Write-Host -Object "$File not found in InnoSetup language folder." -ForegroundColor Yellow
$InnoSetupLanguageMissing = $true
}
}
if ($InnoSetupLanguageMissing) {
Write-Host -Object "You can download the language files here: https://github.com/jrsoftware/issrc/blob/main/Files/Languages/" -ForegroundColor Yellow
}
# Check if InnoSetup is installed
$InnoSetupCompiler = "$InnoSetupPath\ISCC.exe"
if (-not(Test-Path -Path $InnoSetupCompiler -PathType Leaf) -or $InnoSetupLanguageMissing) {
Write-Host -Object "InnoSetup is not installed correctly. Skip installer build..." -ForegroundColor Cyan
}
else {
Start-Process -FilePath $InnoSetupCompiler -ArgumentList """$PSScriptRoot\InnoSetup.iss""" -NoNewWindow -Wait
}
# Create SHA256 file hashes
foreach ($hash in Get-ChildItem -Path $BuildPath | Where-Object { $_.Name.EndsWith(".zip") -or $_.Name.EndsWith(".exe") } | Get-FileHash) {
"$($hash.Algorithm) | $($hash.Hash) | $([System.IO.Path]::GetFileName($hash.Path))" | Out-File -FilePath "$BuildPath\NETworkManager_$($Version)_Hash.txt" -Encoding utf8 -Append
}
# Build finished
Write-Host -Object "`nPackaging finished!`n" -ForegroundColor Green
Write-Host -Object "The following files have been created under`n`n""$BuildPath""`n"
Write-Host -Object "File hashes:`n"
Get-Content -Path "$BuildPath\NETworkManager_$($Version)_Hash.txt"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/netants2018/NETworkManager.git
git@gitee.com:netants2018/NETworkManager.git
netants2018
NETworkManager
NETworkManager
main

搜索帮助