Skip to content

Instantly share code, notes, and snippets.

@mattcorr
Created June 26, 2015 12:21
Show Gist options
  • Save mattcorr/5d77365ff21835824a61 to your computer and use it in GitHub Desktop.
Save mattcorr/5d77365ff21835824a61 to your computer and use it in GitHub Desktop.
Powershell Script for ensuring the BTDF AppsToReference and AppsToRemove definitions are linked correctly across multiple Deployment.btdfproj files
Param ([string]$RootLocalTFSPath)
# Check the path
if (!(Test-Path $RootLocalTFSPath))
{
Write-Host "Unable to find directory '$RootLocalTFSPath'. Please check parameter and try again." -f Red
return
}
# load all Deployment.btdfproj files in the main folder
$configFiles = Get-ChildItem -Path $RootLocalTFSPath -filter *.btdfproj -Recurse | Where-Object {$_.Directory -like "*\main\*"}
foreach ($file in $configFiles)
{
[xml]$data = Get-Content $file.FullName
# get the list of apps to remove
$appsToRemove = $data.Project.ItemGroup.AppsToRemove.Include
$appsToReference = $data.Project.ItemGroup.AppsToReference.Include
# get the application name
$appName = $data.Project.PropertyGroup.ProjectName[0]
Write-Host "Checking $appName`: " -f Cyan -NoNewline; Write-Host $($file.FullName)
if ($appsToRemove -ne $null)
{
Write-Host "Apps to Remove:" -f DarkCyan
foreach ($app in $appsToRemove)
{
Write-Host $app -f Yellow -NoNewline
$linkedFile = $configFiles | Where-Object {$_.Directory -like "*\$app\main\*" }
if ($linkedFile -ne $null)
{
[xml]$linkedData = Get-Content $linkedFile.FullName
if ($linkedData.Project.ItemGroup.AppsToReference.Include -like "*$appName*")
{
Write-Host " [Linked config file has matching AppsToReference defined correctly.]" -f Green
}
else
{
Write-Host " [Linked config file NOT configured correctly.]" -f red
}
}
else
{
Write-Host " [ERROR: Unable to find the Deployment.btdfproj file for '$app'. Is it spelt correctly?]" -f red
}
}
}
else
{
# Should this app have some references to undeploy?
if ($appName -like "*Schemas*" -or
$appName -like "*ReferenceSystems*")
{
Write-Host "No Applications to Remove defined but app name sounds like a Schemas app? Should confirm this." -f Yellow
}
}
if ($appsToReference -ne $null)
{
Write-Host "Apps to Reference:" -f DarkCyan
foreach ($app in $appsToReference)
{
Write-Host $app -f Yellow -NoNewline
$linkedFile = $configFiles | Where-Object {$_.Directory -like "*\$app\main\*" }
if ($linkedFile -ne $null)
{
[xml]$linkedData = Get-Content $linkedFile.FullName
if ($linkedData.Project.ItemGroup.AppsToRemove.Include -like "*$appName*")
{
Write-Host " [Linked config file has matching AppsToRemove defined correctly.]" -f Green
}
else
{
Write-Host " [Linked config file NOT configured correctly.]" -f red
}
}
else
{
Write-Host " [ERROR: Unable to find the Deployment.btdfproj file for '$app'. Is it spelt correctly?]" -f red
}
}
}
Write-Host " "
}
Write-Host "All Done." -f Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment