Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created September 11, 2011 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howarddierking/1209919 to your computer and use it in GitHub Desktop.
Save howarddierking/1209919 to your computer and use it in GitHub Desktop.
powershell script for transforming a codebase
Import-Module Pscx
# the variables you'll likely need to change on your local machine
$afroot = "D:\AppFabric"
$hgroot = 'D:\Programming Projects'
# $hgremote = "https://hg01.codeplex.com/wcf"
$hgremote = "D:\Programming Projects\wcf-codeplex-baseline_RC2"
# derived paths
$afwcfsource = $afroot + "\private\source\WCF"
$afcommonsource = $afroot + "\private\source\Common\Microsoft.Server.Common"
$afwcftestsource = $afroot + "\private\CIT\WCF"
$afcommontest = $afroot + "\private\testcommon"
$clonename = Get-Date -f yyyyMMdd-hhmmss
$hgclonepath = $hgroot + "\wcf-codeplex-baseline_" + $clonename
$hgsrc = $hgclonepath + "\WCFWebApi\Http\Src"
$hgtest = $hgclonepath + "\WCFWebApi\Http\Test"
$enlistmentcmdargs = "/C set inetroot=" + $afroot + "&set corextbranch=appserver&" + $afroot + "\tools\path1st\myenv.cmd"
$enlistmentcmd = "C:\Windows\SysWOW64\cmd.exe"
$bcca = "msbuildcmd /c /a amd64"
$currentpath = Get-Location
# 1.
Start-Process $enlistmentcmd -ArgumentList ($enlistmentcmdargs + "&sd sync") -Wait
# 2.
Start-Process $enlistmentcmd -ArgumentList ($enlistmentcmdargs + "&cd private/source/wcf&" + $bcca) -Wait
# 3.
Start-Process $enlistmentcmd -ArgumentList ($enlistmentcmdargs + "&cd private/source/common/microsoft.server.common&" + $bcca) -Wait
# 4.
Start-Process $enlistmentcmd -ArgumentList ($enlistmentcmdargs + "&cd private/cit/wcf&" + $bcca) -Wait
# 5.
Start-Process $enlistmentcmd -ArgumentList ($enlistmentcmdargs + "&cd private/testcommon&" + $bcca) -Wait
Set-Location $currentpath
#6. (assuming the build is clean) todo: add error handling here
# 7.
hg clone $hgremote $hgclonepath
# 8.
Get-ChildItem $hgsrc | Remove-Item -Recurse
# 9.
Get-ChildItem $afwcfsource `
| where{$_.Name -notlike "Tools*" -and $_.Name -notlike "*Resharper*"} `
| Copy-Item -Destination $hgsrc -Recurse
Copy-Item -Path $afcommonsource -Destination $hgsrc -Recurse
# 10.
Get-ChildItem $hgtest | Remove-Item -Recurse -Force
# 11.
Get-ChildItem $afwcftestsource `
| where{$_.Name -notlike "Tools*" -and $_.Name -notlike "*Resharper*"} `
| Copy-Item -Destination $hgtest -Recurse
Copy-Item -Path ($afcommontest + "\Common") -Destination ($hgtest + "\testcommon\Common") -Recurse
Copy-Item -Path ($afcommontest + "\WCF") -Destination ($hgtest + "\testcommon\WCF") -Recurse
# 12.
# may be able to do this without the temp file hop (http://stackoverflow.com/questions/750449/converting-xml-from-utf-16-to-utf-8-using-powershell)
# -> nope, tried and it still fails with an insufficient access error
$tempfilesuffix = "_TEMP"
$projectfiles = Get-ChildItem $hgsrc -Recurse -Include *.csproj
$projectfiles `
| %{ $filename=$_.FullName; $_ `
| Convert-Xml -XsltPath .\EnlistedCITProj2CodePlexCITProj.xslt `
| Out-File ($filename + $tempfilesuffix) }
$projectfiles | Remove-Item -Force
Get-ChildItem $hgsrc -Recurse -Include ('*.csproj' + $tempfilesuffix) | `
%{ $filepath=$_.FullName; $filename=$_.Name; `
Rename-Item `
-Path $filepath `
-NewName $filename.Substring(0, $filename.LastIndexOf($tempfilesuffix)) }
$testprojectfiles = Get-ChildItem $hgtest -Recurse -Include *.csproj
$testprojectfiles `
| %{ $filename=$_.FullName; $_ `
| Convert-Xml -XsltPath .\EnlistedCITProj2CodePlexCITProj.xslt `
| Out-File ($filename + $tempfilesuffix) }
$testprojectfiles | Remove-Item -Force
Get-ChildItem $hgtest -Recurse -Include ('*.csproj' + $tempfilesuffix) | `
%{ $filepath=$_.FullName; $filename=$_.Name; `
Rename-Item `
-Path $filepath `
-NewName $filename.Substring(0, $filename.LastIndexOf($tempfilesuffix)) }
# 13.
$regex = '(\[assembly:\s?InternalsVisibleTo\(\"[\w\d\.]+)\s?,\s?.+'
$assemblyInfoFiles = Get-ChildItem $hgsrc -Recurse | where{$_.Name -eq "AssemblyInfo.cs"}
$assemblyInfoFiles `
| %{ $filename = $_.FullName; (Get-Content $filename) `
| %{$_ -replace $regex, '$1")]'} `
| Set-Content ($filename + $tempfilesuffix)}
$assemblyInfoFiles | Remove-Item -Force
Get-ChildItem $hgsrc -Recurse -Include ('AssemblyInfo.cs' + $tempfilesuffix) | `
%{ $filepath=$_.FullName; $filename=$_.Name; `
Rename-Item `
-Path $filepath `
-NewName $filename.Substring(0, $filename.LastIndexOf($tempfilesuffix)) }
# 14.
$configregex = '\"([\w\.\d]+\s*,\s*[\w\.\d]+)[,\w\s\d\.=]+\"'
$testconfigpath = $hgtest + "\Microsoft.ApplicationServer.Http\Unit\ConfigFiles"
$testconfigfiles = Get-ChildItem $testconfigpath -Recurse | where{$_.Name -like "*.config"}
$testconfigfiles `
| %{ $filename = $_.FullName; (Get-Content $filename) `
| %{$_ -replace $configregex, '"$1"'} `
| Set-Content ($filename + $tempfilesuffix)}
$testconfigfiles | Remove-Item -Force
Get-ChildItem $testconfigpath -Recurse -Include ('*.config' + $tempfilesuffix) | `
%{ $filepath=$_.FullName; $filename=$_.Name; `
Rename-Item `
-Path $filepath `
-NewName $filename.Substring(0, $filename.LastIndexOf($tempfilesuffix)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment