-
-
Save stephengodbold/967976 to your computer and use it in GitHub Desktop.
Removes source control bindings, and optionally backs up the original 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, | |
[switch] $backup | |
) | |
function killScc(){ | |
gci -path $folder -i *.vssscc,*.vspscc -recurse | Remove-Item -force -verbose | |
} | |
function backupItem([string] $itemPath) { | |
$newPath = $itemPath + '.bak' | |
Write-Verbose 'backing Up ' + $newPath | |
Copy-Item $itemPath $newPath -force | |
} | |
function removeProjectBindings() { | |
gci -path $folder -i *.csproj -recurse | foreach { | |
Write-Verbose 'Modifying ' + $_.FullName | |
[System.Xml.XmlDocument]$proj = get-content $_.FullName | |
if ($backup) { | |
backupItem($_.FullName) | |
} | |
$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 { | |
Write-Verbose 'Modifying ' + $_.FullName | |
if ($backup) { | |
backupItem($_.FullName) | |
} | |
$inSccBlock = $false | |
(get-content $_.FullName) | foreach { | |
if ( $_.Contains('GlobalSection(TeamFoundationVersionControl) = preSolution') ) { $inSccBlock = $true } | |
if ( !$inSccBlock ){ $_ } | |
if ( $_.Contains('EndGlobalSection') ) { $inSccBlock = $false } | |
} | Set-Content $_.FullName -force | |
} | |
} | |
Write-Verbose 'Starting' | |
killScc | |
removeProjectBindings | |
removeSolutionBinding | |
Write-Verbose 'Done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment