新建文件
pack.ps1
目录结构
src Hospital.Fw.ApplicationHospital.Fw.Application.ContractHospital.Fw.DomainHospital.Fw.Domain.SharedHospital.Fw.HttpApiHospital.Fw.SqlSugarCore customHospital.Fw.Domain.Shared.CustomHospital.Fw.HttpApi.Custom moduleHospital.Fw.BackgroundJobsHospital.Fw.InterceptorHospital.Fw.Interceptor.LoggingHospital.Fw.Mo.LoggingHospital.Fw.Permission
脚本
# 获取脚本所在目录 $scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent# 设置输出目录 $outputDir = "C:\Users\Administrator\Desktop\pack"# 创建输出目录(如果不存在) if (-not (Test-Path -Path $outputDir)) {New-Item -ItemType Directory -Path $outputDir }# 定义要处理的父级目录 $parentDirs = @("src", "custom", "module")foreach ($parent in $parentDirs) {# 每次循环父目录前,确保当前路径是脚本所在目录Set-Location $scriptDirif (-not (Test-Path -Path $parent)) {Write-Host "Parent directory not found: $parent" -ForegroundColor Yellowcontinue}Get-ChildItem -Path $parent -Directory | ForEach-Object {$projectDir = $_.FullNameWrite-Host "Entering directory: $projectDir" -ForegroundColor Cyan# 进入子目录并打包Set-Location $projectDirdotnet pack -c release -o $outputDirif ($LASTEXITCODE -eq 0) {Write-Host "Packing succeeded: $projectDir`n" -ForegroundColor Green} else {Write-Host "Packing failed: $projectDir`n" -ForegroundColor Red}# 打包完成后,切换回脚本所在目录Set-Location $scriptDir} }Write-Host "All projects have been packed successfully!"