Skip to content

Commit 58fe3ad

Browse files
committed
Refactor build/test logic and enable multi-targeting
Refactored build.ps1 to unify build and test steps for .NET 8.0 and .NET 10.0, reducing duplication and improving output clarity. Now uses /p:UseNet10=true for multi-targeting when requested. Updated Xcaciv.Loader.csproj to use TargetFrameworks for conditional multi-targeting. Simplified readme.md packaging metadata. Improved summary output and streamlined package copy logic.
1 parent ccc505e commit 58fe3ad

File tree

2 files changed

+44
-128
lines changed

2 files changed

+44
-128
lines changed

build.ps1

Lines changed: 40 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ Write-Host "====================================================="
2828
Write-Host "Xcaciv.Loader Build Script"
2929
Write-Host "====================================================="
3030
if ($Publish) {
31-
Write-Host "Mode: Publish (building for .NET 8.0 and .NET 10.0)" -ForegroundColor Cyan
31+
Write-Host "Mode: Publish" -ForegroundColor Cyan
32+
if ($UseNet10) {
33+
Write-Host "Target Frameworks: .NET 8.0 and .NET 10.0" -ForegroundColor Cyan
34+
} else {
35+
Write-Host "Target Framework: .NET 8.0 only" -ForegroundColor Cyan
36+
}
3237
} elseif ($UseNet10) {
33-
Write-Host "Target Framework: Both .NET 8.0 and .NET 10.0"
38+
Write-Host "Target Frameworks: .NET 8.0 and .NET 10.0"
3439
} else {
35-
Write-Host "Target Framework: .NET 8.0"
40+
Write-Host "Target Framework: .NET 8.0 only"
3641
}
3742
Write-Host "Run Tests: $( if ($Test) { "Yes" } else { "No" } )"
3843
Write-Host "Local NuGet path: $LocalNugetPath"
@@ -43,28 +48,23 @@ if ($Publish) {
4348
}
4449
Write-Host "====================================================="
4550

46-
if ($Publish) {
47-
# Publish mode: Build for both .NET 8 and .NET 10
48-
Write-Host "Building for .NET 8.0..." -ForegroundColor Cyan
49-
$buildCommand = "dotnet build --configuration Release"
50-
Write-Host "Executing: $buildCommand" -ForegroundColor Gray
51-
Invoke-Expression $buildCommand
52-
53-
if ($LASTEXITCODE -ne 0) {
54-
Write-Host "Build failed for .NET 8.0 with exit code $LASTEXITCODE" -ForegroundColor Red
55-
exit $LASTEXITCODE
56-
}
57-
58-
Write-Host "Building for .NET 10.0..." -ForegroundColor Cyan
51+
# Build
52+
Write-Host "Building solution..." -ForegroundColor Cyan
53+
if ($UseNet10) {
5954
$buildCommand = "dotnet build --configuration Release /p:UseNet10=true"
60-
Write-Host "Executing: $buildCommand" -ForegroundColor Gray
61-
Invoke-Expression $buildCommand
62-
63-
if ($LASTEXITCODE -ne 0) {
64-
Write-Host "Build failed for .NET 10.0 with exit code $LASTEXITCODE" -ForegroundColor Red
65-
exit $LASTEXITCODE
66-
}
67-
55+
} else {
56+
$buildCommand = "dotnet build --configuration Release"
57+
}
58+
Write-Host "Executing: $buildCommand" -ForegroundColor Gray
59+
Invoke-Expression $buildCommand
60+
61+
if ($LASTEXITCODE -ne 0) {
62+
Write-Host "Build failed with exit code $LASTEXITCODE" -ForegroundColor Red
63+
exit $LASTEXITCODE
64+
}
65+
66+
# If publishing, copy packages to publish directory
67+
if ($Publish) {
6868
# Create publish directory
6969
$publishDir = Join-Path $PSScriptRoot "publish"
7070
if (Test-Path $publishDir) {
@@ -97,7 +97,7 @@ if ($Publish) {
9797
Write-Host "Copied $copiedCount package(s) to publish directory" -ForegroundColor Green
9898
}
9999

100-
# Mandatory local copy to NuGet packages directory (only if directory exists)
100+
# Copy to local NuGet packages directory
101101
if ([string]::IsNullOrWhiteSpace($LocalNugetPath)) {
102102
Write-Host "Warning: LocalNugetPath is not specified, skipping local copy" -ForegroundColor Yellow
103103
} else {
@@ -126,99 +126,21 @@ if ($Publish) {
126126
exit 1
127127
}
128128
}
129-
130-
} else {
131-
# Standard build mode
132-
if ($UseNet10) {
133-
# Build for both .NET 8 and .NET 10
134-
Write-Host "Building for .NET 8.0..." -ForegroundColor Cyan
135-
$buildCommand = "dotnet build --configuration Release"
136-
Write-Host "Executing: $buildCommand" -ForegroundColor Gray
137-
Invoke-Expression $buildCommand
138-
139-
if ($LASTEXITCODE -ne 0) {
140-
Write-Host "Build failed for .NET 8.0 with exit code $LASTEXITCODE" -ForegroundColor Red
141-
exit $LASTEXITCODE
142-
}
143-
144-
Write-Host "Building for .NET 10.0..." -ForegroundColor Cyan
145-
$buildCommand = "dotnet build --configuration Release /p:UseNet10=true"
146-
Write-Host "Executing: $buildCommand" -ForegroundColor Gray
147-
Invoke-Expression $buildCommand
148-
149-
if ($LASTEXITCODE -ne 0) {
150-
Write-Host "Build failed for .NET 10.0 with exit code $LASTEXITCODE" -ForegroundColor Red
151-
exit $LASTEXITCODE
152-
}
153-
} else {
154-
# Build for .NET 8 only
155-
Write-Host "Building solution..." -ForegroundColor Cyan
156-
$buildCommand = "dotnet build --configuration Release"
157-
Write-Host "Executing: $buildCommand" -ForegroundColor Gray
158-
Invoke-Expression $buildCommand
159-
160-
if ($LASTEXITCODE -ne 0) {
161-
Write-Host "Build failed with exit code $LASTEXITCODE" -ForegroundColor Red
162-
exit $LASTEXITCODE
163-
}
164-
}
165129
}
166130

167131
# Run tests if requested
168132
if ($Test) {
169-
if ($Publish) {
170-
# Run tests for both frameworks
171-
Write-Host "Running tests for .NET 8.0..." -ForegroundColor Cyan
172-
$testCommand = "dotnet test --no-build --configuration Release"
173-
Write-Host "Executing: $testCommand" -ForegroundColor Gray
174-
Invoke-Expression $testCommand
175-
176-
if ($LASTEXITCODE -ne 0) {
177-
Write-Host "Tests failed for .NET 8.0 with exit code $LASTEXITCODE" -ForegroundColor Red
178-
exit $LASTEXITCODE
179-
}
180-
181-
Write-Host "Running tests for .NET 10.0..." -ForegroundColor Cyan
182-
$testCommand = "dotnet test --no-build --configuration Release /p:UseNet10=true"
183-
Write-Host "Executing: $testCommand" -ForegroundColor Gray
184-
Invoke-Expression $testCommand
185-
186-
if ($LASTEXITCODE -ne 0) {
187-
Write-Host "Tests failed for .NET 10.0 with exit code $LASTEXITCODE" -ForegroundColor Red
188-
exit $LASTEXITCODE
189-
}
190-
} elseif ($UseNet10) {
191-
# Run tests for both frameworks
192-
Write-Host "Running tests for .NET 8.0..." -ForegroundColor Cyan
193-
$testCommand = "dotnet test --no-build --configuration Release"
194-
Write-Host "Executing: $testCommand" -ForegroundColor Gray
195-
Invoke-Expression $testCommand
196-
197-
if ($LASTEXITCODE -ne 0) {
198-
Write-Host "Tests failed for .NET 8.0 with exit code $LASTEXITCODE" -ForegroundColor Red
199-
exit $LASTEXITCODE
200-
}
201-
202-
Write-Host "Running tests for .NET 10.0..." -ForegroundColor Cyan
203-
$testCommand = "dotnet test --no-build --configuration Release /p:UseNet10=true"
204-
Write-Host "Executing: $testCommand" -ForegroundColor Gray
205-
Invoke-Expression $testCommand
206-
207-
if ($LASTEXITCODE -ne 0) {
208-
Write-Host "Tests failed for .NET 10.0 with exit code $LASTEXITCODE" -ForegroundColor Red
209-
exit $LASTEXITCODE
210-
}
211-
} else {
212-
# Standard test mode (.NET 8 only)
213-
Write-Host "Running tests..." -ForegroundColor Cyan
214-
$testCommand = "dotnet test --no-build --configuration Release"
215-
Write-Host "Executing: $testCommand" -ForegroundColor Gray
216-
Invoke-Expression $testCommand
217-
218-
if ($LASTEXITCODE -ne 0) {
219-
Write-Host "Tests failed with exit code $LASTEXITCODE" -ForegroundColor Red
220-
exit $LASTEXITCODE
221-
}
133+
Write-Host "Running tests..." -ForegroundColor Cyan
134+
$testCommand = "dotnet test --no-build --configuration Release"
135+
if ($UseNet10) {
136+
$testCommand += " /p:UseNet10=true"
137+
}
138+
Write-Host "Executing: $testCommand" -ForegroundColor Gray
139+
Invoke-Expression $testCommand
140+
141+
if ($LASTEXITCODE -ne 0) {
142+
Write-Host "Tests failed with exit code $LASTEXITCODE" -ForegroundColor Red
143+
exit $LASTEXITCODE
222144
}
223145
}
224146

@@ -271,16 +193,15 @@ if ($Publish) {
271193
}
272194
}
273195

196+
# Final summary
197+
Write-Host "====================================================="
274198
if ($Publish) {
275-
Write-Host "====================================================="
276199
Write-Host "Publish completed successfully!" -ForegroundColor Green
277200
Write-Host "Packages available in: $(Join-Path $PSScriptRoot 'publish')" -ForegroundColor Cyan
278201
if (-not [string]::IsNullOrWhiteSpace($LocalNugetPath)) {
279202
Write-Host "Local packages copied to: $LocalNugetPath" -ForegroundColor Cyan
280203
}
281-
Write-Host "====================================================="
282204
} else {
283-
Write-Host "====================================================="
284205
Write-Host "Build completed successfully!" -ForegroundColor Green
285-
Write-Host "====================================================="
286-
}
206+
}
207+
Write-Host "====================================================="

src/Xcaciv.Loader/Xcaciv.Loader.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<!-- Target Framework -->
4-
<TargetFramework>net8.0</TargetFramework>
5-
<!-- Define a property to conditionally switch to .NET 10 -->
6-
<UseNet10 Condition="'$(UseNet10)' == ''">false</UseNet10>
7-
<TargetFramework Condition="'$(UseNet10)' == 'true'">net10.0</TargetFramework>
3+
<!-- Target Frameworks - Build for both .NET 8 and .NET 10 by default -->
4+
<TargetFrameworks Condition="'$(UseNet10)' == 'true'">net8.0;net10.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(UseNet10)' != 'true'">net8.0</TargetFrameworks>
86

97
<!-- Version Information -->
108
<Version>2.1.1</Version>
@@ -97,10 +95,7 @@ See CHANGELOG.md for complete details and migration guide.
9795

9896
<!-- Package Content -->
9997
<ItemGroup>
100-
<None Update="readme.md">
101-
<Pack>True</Pack>
102-
<PackagePath>\</PackagePath>
103-
</None>
98+
<None Include="readme.md" Pack="true" PackagePath="\" />
10499
</ItemGroup>
105100

106101
<!-- Source Link Package -->

0 commit comments

Comments
 (0)