Add PowerShell cmdlets and update project structure

This commit is contained in:
GraceSolutions
2025-04-10 21:13:24 -04:00
parent e5a7f10ade
commit 7cd5962115
56 changed files with 2356 additions and 3914 deletions
+70 -28
View File
@@ -1,37 +1,79 @@
# Build script for WindowsNotifications
#
# build.ps1
# Build script for the Windows Notifications library
#
param (
[switch]$Clean,
[switch]$Release,
[switch]$Test
)
# Set the configuration
$Configuration = "Release"
$configuration = if ($Release) { "Release" } else { "Debug" }
# Check if dotnet CLI is available
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
if (-not $dotnetPath) {
Write-Host "The .NET SDK is not installed or not in the PATH. Please install the .NET SDK." -ForegroundColor Red
# Set the MSBuild path
$msbuildPath = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
if (-not (Test-Path $msbuildPath)) {
Write-Error "MSBuild not found at $msbuildPath"
exit 1
}
# Clean the solution
Write-Host "Cleaning solution..." -ForegroundColor Cyan
dotnet clean WindowsNotifications.sln --configuration $Configuration
# Restore NuGet packages
Write-Host "Restoring NuGet packages..." -ForegroundColor Cyan
dotnet restore WindowsNotifications.sln
# Clean the solution if requested
if ($Clean) {
Write-Host "Cleaning solution..."
& $msbuildPath "WindowsNotifications.sln" /t:Clean /p:Configuration=$configuration /v:minimal
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to clean solution"
exit 1
}
}
# Build the solution
Write-Host "Building solution..." -ForegroundColor Cyan
dotnet build WindowsNotifications.sln --configuration $Configuration --no-restore
# Check if the build was successful
if ($LASTEXITCODE -eq 0) {
Write-Host "Build completed successfully!" -ForegroundColor Green
# Show the output directory
$outputDir = Join-Path -Path $PSScriptRoot -ChildPath "WindowsNotifications\bin\$Configuration"
Write-Host "Output directory: $outputDir" -ForegroundColor Yellow
# List the files in the output directory
Get-ChildItem -Path $outputDir | Format-Table Name, Length
} else {
Write-Host "Build failed with exit code $LASTEXITCODE" -ForegroundColor Red
Write-Host "Building solution in $configuration configuration..."
& $msbuildPath "WindowsNotifications.sln" /t:Build /p:Configuration=$configuration /v:minimal
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build solution"
exit 1
}
# Run tests if requested
if ($Test) {
Write-Host "Running tests..."
$testDll = "WindowsNotifications.Tests\bin\$configuration\WindowsNotifications.Tests.dll"
if (-not (Test-Path $testDll)) {
Write-Error "Test DLL not found at $testDll"
exit 1
}
# Try to find NUnit console runner
$nunitPath = "packages\NUnit.ConsoleRunner\tools\nunit3-console.exe"
if (-not (Test-Path $nunitPath)) {
Write-Host "NUnit console runner not found, installing..."
& nuget install NUnit.ConsoleRunner -OutputDirectory packages
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to install NUnit console runner"
exit 1
}
$nunitPath = (Get-ChildItem -Path "packages" -Filter "nunit3-console.exe" -Recurse).FullName
if (-not $nunitPath) {
Write-Error "NUnit console runner not found after installation"
exit 1
}
}
& $nunitPath $testDll
if ($LASTEXITCODE -ne 0) {
Write-Error "Tests failed"
exit 1
}
}
# Copy the DLL to the PowerShell module directory
Write-Host "Copying DLL to PowerShell module directory..."
$dllPath = "WindowsNotifications\bin\$configuration\WindowsNotifications.dll"
$modulePath = "PowerShell\WindowsNotifications.dll"
Copy-Item -Path $dllPath -Destination $modulePath -Force
Write-Host "Build completed successfully"