Skip to content

Commit 6f181e6

Browse files
committed
wrote on a script for a better linux deployment
1 parent 085f7b1 commit 6f181e6

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

Source/VisualPairCoding/VisualPairCoding.AvaloniaUI/VisualPairCoding.AvaloniaUI.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputType>WinExe</OutputType>
3+
<OutputType>Exe</OutputType>
44
<TargetFramework>net7.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
77
<TrimMode>copyused</TrimMode>
8-
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
8+
<BuiltInComInteropSupport>false</BuiltInComInteropSupport>
9+
<SelfContained>true</SelfContained>
10+
<PublishSingleFile>true</PublishSingleFile>
911
</PropertyGroup>
1012
<ItemGroup>
1113
<None Remove=".gitignore" />

build-linux.ps1

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

build.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Set-Location $PSScriptRoot
2+
3+
. .\build-linux.ps1

0 commit comments

Comments
 (0)