-
-
Save jstangroome/858167 to your computer and use it in GitHub Desktop.
Strip source control bindings from solution and project files
This file contains 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
#requires -version 2.0 | |
param ( | |
[ValidateScript({$_ | Test-Path -PathType Container})] | |
[Parameter(Mandatory=$true)] | |
[string] $folder | |
) | |
function killScc(){ | |
gci -path $folder -i *.vssscc,*.vspscc -recurse | Remove-Item -force -verbose | |
} | |
function removeProjectBindings() { | |
gci -path $folder -i *.csproj -recurse | foreach { | |
'Modifying ' + $_.FullName | |
[System.Xml.XmlDocument]$proj = get-content $_.FullName | |
$newPath = $_.FullName + '.bak' | |
'backing Up ' + $newPath | |
Copy-Item $_.FullName $newPath -force | |
$ns = New-Object Xml.XmlNamespaceManager($proj.PSBase.NameTable) | |
$ns.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003") | |
'SccProjectName', 'SccLocalPath', 'SccProvider' | foreach { | |
$node = $proj.SelectSingleNode('//msb:' + $_ , $ns) | |
if ( $node ) { $x = $node.ParentNode.RemoveChild($node) } | |
} | |
$_ | Remove-Item -force | |
$proj.Save($_.FullName) | |
} | |
} | |
function removeSolutionBinding() { | |
gci -path $folder -i *.sln -recurse | foreach { | |
'Modifying ' + $_.FullName | |
$newPath = $_.FullName + '.bak' | |
'backing Up ' + $newPath | |
Copy-Item $_.FullName $newPath -force | |
$inSccBlock = $false | |
(get-content $_.FullName) | foreach { | |
if ( $_.Contains('GlobalSection(SourceCodeControl) = preSolution') ) { $inSccBlock = $true } | |
if ( !$inSccBlock ){ $_ } | |
if ( $_.Contains('EndGlobalSection') ) { $inSccBlock = $false } | |
} | Set-Content $_.FullName -force | |
} | |
} | |
'Starting' | |
killScc | |
removeProjectBindings | |
removeSolutionBinding | |
'Done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment