Created
October 10, 2022 06:29
-
-
Save vadimblv/83f3b0bdc51dae23f56a17a217bbce7a to your computer and use it in GitHub Desktop.
Remove-Binding-Redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://martowen.com/2018/09/12/refreshing-net-assembly-binding-redirects-in-a-visual-studio-solution/ | |
function Remove-BindingRedirect { | |
param( | |
[parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
[object[]] | |
$Project | |
) | |
process { | |
$ProjectDir = Split-Path $Project.FullName | |
$ConfigFileName = $Project.ProjectItems | Where-Object { $_.Name -eq 'web.config' -or $_.Name -eq 'app.config' -or $_.Name -eq 'App.config' -or $_.Name -eq 'App.Master.config' -or $_.Name -eq 'Web.Master.config' } | |
if ($null -ne $ConfigFileName) { | |
$ConfigPath = Join-Path -Path $ProjectDir -ChildPath $ConfigFileName.Name | |
$Xml = [xml](Get-Content $ConfigPath) | |
$Ns = @{ ms = "urn:schemas-microsoft-com:asm.v1" } | |
$Xml | Select-Xml '//ms:assemblyBinding' -Namespace $Ns | ForEach-Object { | |
$Xml.configuration.runtime.RemoveChild($_.Node) | |
} | Out-Null | |
$Xml.Save($ConfigPath) | |
Write-Host "Removed bindingRedirects from $ConfigPath" | |
} | |
else { | |
Write-Host "Couldn't remove bindingRedirects from $($Project.Name) as couldn't find a config file" | |
} | |
return $Project | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment