Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save evilpilaf/7b17ca99a58d4f053ffb6fcba9eb01f4 to your computer and use it in GitHub Desktop.

Select an option

Save evilpilaf/7b17ca99a58d4f053ffb6fcba9eb01f4 to your computer and use it in GitHub Desktop.

Revisions

  1. @dburriss dburriss created this gist Feb 27, 2018.
    25 changes: 25 additions & 0 deletions print-binding-redirects.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    function Find-Dlls() {
    $dlls = Get-ChildItem | ? { $_.Extension -eq '.dll' } | % { [System.Reflection.AssemblyName]::GetAssemblyName($_.FullName).FullName }
    return $dlls
    }

    function Set-Bindings() {
    $binding = "<dependentAssembly>
    <assemblyIdentity name=`"{0}`" publicKeyToken=`"{2}`" culture=`"neutral`" />
    <bindingRedirect oldVersion=`"0.0.0.0-{1}`" newVersion=`"{1}`" />
    </dependentAssembly>"
    $dlls = Find-Dlls
    $bindings = new-object string[] $dlls.length
    for ($i=0; $i -lt $dlls.length; $i++) {
    $values = $dlls[$i] -replace "([^,]+), Version=([^,]+), Culture=neutral, PublicKeyToken=(.*)", '$1,$2,$3'
    $current = $binding -f $values.split(",")
    $bindings[$i] = $current
    }

    foreach($binding in $bindings){
    Write-Host $binding
    }
    }

    Set-Bindings()