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