-
-
Save SirkleZero/2792612 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
param ( | |
[ValidateScript({$_ | Test-Path -PathType Container})] | |
[Parameter(Mandatory=$true)] | |
[string] $folder, | |
[switch] $backup | |
) | |
function killReadOnlyFlag(){ | |
get-childitem "$folder" -recurse | % { | |
# Test for ReadOnly flag and remove if present | |
if ($_.attributes -band [system.IO.FileAttributes]::ReadOnly) | |
{ | |
$_.attributes = $_.attributes -bxor [system.IO.FileAttributes]::ReadOnly | |
Write-Host "Removing read-only flag " $_.FullName | |
} | |
} | |
} | |
function killScc(){ | |
gci -path $folder -recurse -force -i *.suo, *.*scc, *.user | Remove-Item -force -verbose | |
} | |
function backupItem([string] $itemPath) { | |
$newPath = $itemPath + ".bak" | |
Write-Host "backing Up " $newPath | |
Copy-Item $itemPath $newPath -force | |
} | |
function removeProjectBindings() { | |
gci -path $folder -i *.csproj, *.dbproj -recurse | foreach { | |
Write-Host "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", "SccAuxPath" | foreach { | |
$node = $proj.SelectSingleNode("//msb:" + $_ , $ns) | |
if ( $node ) { $x = $node.ParentNode.RemoveChild($node) } | |
} | |
$_ | Remove-Item -force | |
$proj.Save($_.FullName) | |
} | |
} | |
function removeLegacyDatabaseProjectBinding(){ | |
gci -path $folder -i *.dbp -recurse | foreach { | |
Write-Host "Modifying " $_.FullName | |
if ($backup) { | |
backupItem($_.FullName) | |
} | |
(get-content $_.FullName) | foreach { | |
if(!$_.Contains("SccProjectName") -and !$_.Contains("SccLocalPath") -and !$_.Contains("SccAuxPath") -and !$_.Contains("SccProvider")){ | |
$_ | |
} | |
} | Set-Content $_.FullName -force | |
} | |
} | |
function removeSolutionBinding() { | |
gci -path $folder -i *.sln -recurse | foreach { | |
Write-Host "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-Host "Running..." | |
[System.Reflection.Assembly]::LoadWithPartialName(“System.Diagnostics”) | |
$sw = new-object system.diagnostics.stopwatch | |
$sw.Start() | |
killReadOnlyFlag | |
killScc | |
removeProjectBindings | |
removeLegacyDatabaseProjectBinding | |
removeSolutionBinding | |
$sw.Stop() | |
Write-Host "Completed in " $sw.Elapsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This variation adds the ability to remove the read-only flags that TFS puts on all project files as well as handle some older database project types.