Skip to content

Instantly share code, notes, and snippets.

Created March 7, 2011 03:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/858013 to your computer and use it in GitHub Desktop.
Save anonymous/858013 to your computer and use it in GitHub Desktop.
Removes scc bindings from a Visual Studio solution
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