Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Forked from anonymous/killscc.ps1
Created March 7, 2011 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jstangroome/858167 to your computer and use it in GitHub Desktop.
Save jstangroome/858167 to your computer and use it in GitHub Desktop.
Strip source control bindings from solution and project files
#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