Replace version in AssemblyInfo.cs

Date: 2023-03-20
$ver = $env:MY_PACKAGE_VERSION
$files = Get-ChildItem -Path "." -Filter AssemblyInfo.cs -Recurse
foreach ($file in $files) {
    $fn = $file.FullName
    Write-Host "Replacing '$ver' in $fn"
    $c = Get-Content -Path $fn -Raw
    $c = $c -replace '(?m)(?<=AssemblyVersion\(").*(?="\))', $ver -replace '(?m)(?<=AssemblyFileVersion\(").*(?="\))', $ver
    Set-Content -Path $fn -Value $c
    $c = Get-Content -Path $fn -Raw
    $n = ([regex]::Matches($c, [Regex]::Escape($ver))).count;
    Write-Host "Replaced $n times"
}
75850cookie-checkReplace version in AssemblyInfo.cs