Skip to content

Instantly share code, notes, and snippets.

@dburriss
Created February 27, 2018 20:57
Show Gist options
  • Save dburriss/5eda8d40fc03157a1ac92dfe74b560a5 to your computer and use it in GitHub Desktop.
Save dburriss/5eda8d40fc03157a1ac92dfe74b560a5 to your computer and use it in GitHub Desktop.
Print out the binding redirects in a bin folder. Run from the build output directory.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment