Created
March 7, 2011 03:24
-
-
Save anonymous/858013 to your computer and use it in GitHub Desktop.
Removes scc bindings from a Visual Studio solution
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
param([string] $folder) | |
$keys = 'SccProjectName', 'SccLocalPath', 'SccProvider', 'SccAuxPath' | |
$extensions = '.vssscc', '.vspscc' | |
function killScc(){ | |
gci $folder -recurse | Where-Object { $extensions -contains $_.Extension } | foreach { | |
'Deleting ' + $_.FullName | |
$_ | Remove-Item -force | |
} | |
} | |
function removeProjectBindings() { | |
gci $folder -recurse | Where-Object { $_.Extension -eq '.csproj' } | foreach { | |
'Modifying ' + $_.FullName | |
[System.Xml.XmlDocument]$proj = get-content $_.FullName | |
$ns = New-Object Xml.XmlNamespaceManager($proj.PSBase.NameTable) | |
$ns.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003") | |
$keys | foreach { | |
$node = $proj.SelectSingleNode('//msb:' + $_ , $ns) | |
if ( $node ) { $x = $node.ParentNode.RemoveChild($node) } | |
} | |
$proj.Save($_.FullName) | |
} | |
} | |
function removeSolutionBinding() { | |
gci $folder -recurse | Where-Object { $_.Extension -eq '.sln' } | foreach { | |
'Modifying ' + $_.FullName | |
$sln = get-content $_.FullName | |
#container For Good Lines | |
$newSln = @() | |
$inSccBlock = $false | |
$sln | foreach { | |
$line = $_ | |
#Check to see if it's a known source control block | |
$sectionKeys = 'SourceCodeControl', 'TeamFoundationVersionControl' | |
$sectionKeys | foreach { | |
if ( $line.Contains('GlobalSection(' + $_ + ')') ) { | |
$inSccBlock = $true | |
} | |
} | |
if ( !$inSccBlock ){ | |
#check we don't have extra scc keys (web projects) | |
$hasKey = $false | |
$keys | foreach { | |
if ( $line.Contains($_) ) { $hasKey = $true } | |
} | |
#if it's all good, keep the line | |
if ( $hasKey -eq $false ) { $newSln += $line } | |
} | |
if ( $line.Contains('EndGlobalSection') ) { $inSccBlock = $false } | |
} | |
$newSln | Set-Content $_.FullName -force | |
} | |
} | |
if ( ($folder -eq $null) -or ([System.IO.Directory]::Exists($folder) -eq $false) ) | |
{ | |
"usage : .\killscc.ps1 (path to folder)" | |
} | |
else | |
{ | |
'Starting' | |
'Removing Read Only flags' | |
gci $folder -recurse | Where-Object { $_.PSIsContainer -eq $false} | Set-ItemProperty -name IsReadOnly -value $false -force | |
killScc | |
removeProjectBindings | |
removeSolutionBinding | |
'Done' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment