Powershell script to remove Visual Source Safe References

I am migrating a codebase from Visual Source Safe (yes, in 2015, still VSS) to Git. One issue is the pesky way in which VSS embeds references to itself all over the place. Brian Carroll has a nice list of the things that need to be deleted here.

The project I'm working on has dozens of solution & project files spread through a large folder hierarchy, and I really didn't want to edit each file by hand. So, I wrote the following Powershell script. This was tested using Powershell 3.0 and should work for any project.  Only the $rootFolder value would need to be changed or converted into a script parameter.

$rootFolder = "C:\Projects\Workspace\KillVSSTest"

Get-ChildItem $rootFolder -Recurse -File | Set-ItemProperty -Name IsReadOnly -value $false

Get-ChildItem $rootFolder -include *.scc, *.vssscc, *.vspscc -Recurse | Remove-Item  -Force

Function RemoveTextInclusive($beginningText, $endingText, $includeFiles) {
    Get-ChildItem $rootFolder -include $includeFiles -Recurse | ForEach-Object {
        $text = [IO.File]::ReadAllText($_.FullName)
        $text = $text -replace "$beginningText(.|\n)*?$endingText", ""
        $text | Out-File $_.FullName -Force utf8
    }
}

RemoveTextInclusive "\s*GlobalSection\(SourceCodeControl\)" "EndGlobalSection" @("*.sln")
RemoveTextInclusive "\s*\" "\<\/SccProjectName\>" @("*.vcxproj","*.csproj","*.vbproj")
RemoveTextInclusive "\s*\" "\<\/SccAuxPath\>" @("*.vcxproj","*.csproj","*.vbproj")
RemoveTextInclusive "\s*\" "\<\/SccLocalPath\>" @("*.vcxproj","*.csproj","*.vbproj")
RemoveTextInclusive "\s*\" "\<\/SccProvider\>" @("*.vcxproj","*.csproj","*.vbproj")

Comments

Popular posts from this blog

Fixing Conan Lock Issues

Dynamic Object Oriented programming in ArchestrA

Initialize With Care