Repository navigation
Expand file tree
/
Copy pathBuild.ps1
More file actions
63 lines (53 loc) · 2.18 KB
/
Copy pathBuild.ps1
File metadata and controls
63 lines (53 loc) · 2.18 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
<#
.SYNOPSIS
Builds the WebSocketUtils project and runs tests.
.DESCRIPTION
Restores dependencies, optionally cleans, builds the library, runs unit tests, and optionally packs a NuGet package.
#>
param (
[string]$ProjectPath = ".\WebSocketUtils\WebSocketUtils.csproj",
[string]$TestProjectPath = ".\WebSocketUtils.Tests\WebSocketUtils.Tests.csproj",
[string]$Configuration = "Release",
[switch]$Pack,
[switch]$Clean
)
# Ensure .NET SDK is installed
if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) {
Write-Error "dotnet SDK not found. Please install .NET SDK to continue."
exit 1
}
# Clean if requested
if ($Clean) {
Write-Host "Cleaning project $ProjectPath ..."
dotnet clean $ProjectPath --configuration $Configuration
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if (Test-Path $TestProjectPath) {
Write-Host "Cleaning test project $TestProjectPath ..."
dotnet clean $TestProjectPath --configuration $Configuration
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
}
Write-Host "Restoring packages for $ProjectPath ..."
dotnet restore $ProjectPath
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "Building $ProjectPath in $Configuration configuration ..."
dotnet build $ProjectPath --configuration $Configuration
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# Build and run the test project
if (Test-Path $TestProjectPath) {
Write-Host "Building test project $TestProjectPath ..."
dotnet build $TestProjectPath --configuration $Configuration
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "Running tests for $TestProjectPath ..."
dotnet test $TestProjectPath --configuration $Configuration --logger "console;verbosity=detailed"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} else {
Write-Warning "Test project not found at $TestProjectPath. Skipping tests."
}
if ($Pack) {
Write-Host "Packing $ProjectPath as NuGet package ..."
dotnet pack $ProjectPath --configuration $Configuration --output ".\nupkg"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "NuGet package created in .\nupkg"
}
Write-Host "Build and test completed successfully."