$csProjPath = Join-Path $PSScriptRoot "../src/Extensions/Extensions.csproj"

$frameworks = ((Select-String -Path $csProjPath -Pattern '(<TargetFramework[s]?>)').Line).Trim() -replace '<.*?>'
foreach ($framework in $frameworks -split ";") {
    $framework = $framework.Trim()

    Write-Host "Building extensions.csproj for '$framework'"

    $outputPath = Join-Path $PSScriptRoot "../dist/build/$framework"
    dotnet build $csProjPath -c Release -f $framework -o $outputPath

    $destination = $PSScriptRoot

    if ($framework -ne "net48") {
        $destination += "/netcore"

        if (-not (Test-Path $destination)) {
            New-Item $destination -ItemType Directory
        }
    }

    Copy-Item -Path "$($outputPath)/Extensions.dll" -Destination $destination
}
