ex-ex-02-books/server/run.ps1
github-classroom[bot] 49d2d70965
Initial commit
2025-06-03 15:21:16 +00:00

40 lines
No EOL
1.3 KiB
PowerShell

$dotnetVersionStr = (& dotnet --version).Trim()
try {
$dotnetVersion = [version]$dotnetVersionStr
} catch {
Write-Error "Unable to parse dotnet version: $dotnetVersionStr"
exit 1
}
$csprojFile = Get-ChildItem -Path . -Filter *.csproj | Select-Object -First 1
if (-not $csprojFile) {
Write-Host "No csproj file found in the current directory."
exit 1
}
[xml]$csprojXml = Get-Content $csprojFile.FullName
$targetFramework = $csprojXml.Project.PropertyGroup.TargetFramework
if (-not $targetFramework) {
Write-Host "TargetFramework element not found in $($csprojFile.Name)."
exit 1
}
if ($targetFramework -match 'net(\d+(\.\d+)?)') {
$requiredVersionStr = $matches[1]
try {
$requiredVersion = [version]$requiredVersionStr
} catch {
Write-Host "Unable to parse required version: $requiredVersionStr"
exit 1
}
} else {
Write-Host "Unrecognized TargetFramework format: $targetFramework"
exit 1
}
if ($dotnetVersion -lt $requiredVersion) {
Write-Warning "Your dotnet version ($dotnetVersion) is outdated. Go to https://get.dot.net and download the latest SDK"
} else {
Write-Host "Your dotnet version ($dotnetVersion) is up to date"
Write-Host "Starting the server - keep the console window open!"
dotnet run
}