|
| 1 | +function Write-MessageInFrame { |
| 2 | + [CmdletBinding()] |
| 3 | + param ( |
| 4 | + [Parameter(Mandatory = $true)] |
| 5 | + [string]$Message |
| 6 | + ) |
| 7 | + |
| 8 | + $borderChar = "+" |
| 9 | + $paddingChar = " " |
| 10 | + $termWidth = $Host.UI.RawUI.WindowSize.Width |
| 11 | + $maxLength = ($Message | Measure-Object -Maximum -Property Length).Maximum |
| 12 | + $borderLength = [math]::Max($maxLength + 4, $termWidth) |
| 13 | + $border = $borderChar * $borderLength |
| 14 | + |
| 15 | + |
| 16 | + Write-Host "" |
| 17 | + Write-Host $border |
| 18 | + Write-Host "$borderChar$paddingChar$Message$paddingChar$borderChar" |
| 19 | + Write-Host $border |
| 20 | + Write-Host "" |
| 21 | +} |
| 22 | + |
| 23 | +function Get-NonLibraryCsprojFiles { |
| 24 | + [CmdletBinding()] |
| 25 | + param ( |
| 26 | + [Parameter(Mandatory = $true)] |
| 27 | + [string]$Path |
| 28 | + ) |
| 29 | + |
| 30 | + # Find all csproj files in the directory |
| 31 | + $csprojFiles = Get-ChildItem -Path $Path -Recurse -Include *.csproj |
| 32 | + |
| 33 | + # Loop through each csproj file and check its output type |
| 34 | + foreach ($csproj in $csprojFiles) { |
| 35 | + $xml = [xml](Get-Content $csproj.FullName) |
| 36 | + $outputType = $xml.Project.PropertyGroup.OutputType |
| 37 | + |
| 38 | + if ($outputType -in "WinExe", "Exe") { |
| 39 | + $csproj.FullName |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +$outputDirectory = "$PSScriptRoot\output" |
| 46 | +$slnFile = Get-ChildItem -Recurse -Filter *.sln -ErrorAction SilentlyContinue |
| 47 | + |
| 48 | +if (Test-Path $outputDirectory) { |
| 49 | + Remove-Item $outputDirectory -Recurse |
| 50 | +} |
| 51 | + |
| 52 | +if (-not([bool]$slnFile)) { |
| 53 | + Write-Host "No .sln file was found in the specified folder or its subfolders." |
| 54 | +} |
| 55 | + |
| 56 | +Push-Location -Path $slnFile.DirectoryName |
| 57 | + |
| 58 | +Write-MessageInFrame "$($slnFile.FullName) building..." |
| 59 | +dotnet build --configuration Release |
| 60 | +if ($LASTEXITCODE -gt 0) { |
| 61 | + Write-Error "Build failed with exit code $($LASTEXITCODE)" |
| 62 | + exit $LASTEXITCODE |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +Write-MessageInFrame "testing" |
| 67 | + |
| 68 | +dotnet test |
| 69 | +if ($LASTEXITCODE -gt 0) { |
| 70 | + Write-Error "Build failed with exit code $($LASTEXITCODE)" |
| 71 | + exit $LASTEXITCODE |
| 72 | +} |
| 73 | + |
| 74 | +Write-MessageInFrame "publish" |
| 75 | + |
| 76 | +#dotnet publish $($slnFile.FullName) --configuration Release --runtime linux-x64 --self-contained true --output $outputDirectory /p:PublishSingleFile=true /p:IncludeSymbols=false /p:DebugType=None |
| 77 | +$projects_to_publish = Get-NonLibraryCsprojFiles ./ |
| 78 | + |
| 79 | +if ([bool]$projects_to_publish) { |
| 80 | + $projects_to_publish | Foreach-Object { |
| 81 | + $currentProject = $_ |
| 82 | + |
| 83 | + $relativePath = "./" + $currentProject.Substring($slnFile.DirectoryName.Length + 1) |
| 84 | + Write-Host " -> $relativePath" -ForegroundColor Cyan |
| 85 | + |
| 86 | + dotnet publish $relativePath --configuration Release --output $outputDirectory /p:IncludeSymbols=false /p:DebugType=None |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +if ($LASTEXITCODE -gt 0) { |
| 91 | + Write-Error "Publishing failed with exit code $($LASTEXITCODE)" |
| 92 | + exit $LASTEXITCODE |
| 93 | +} |
| 94 | + |
| 95 | +Pop-Location |
0 commit comments