Created
May 14, 2015 14:54
-
-
Save Badgerati/78a3366dce87a25c1c8a to your computer and use it in GitHub Desktop.
PowerShell script for cleaning multiple projects/solutions in one command line via MSBuild
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
########################################################################### | |
# Author: Matthew Kelly (@Badgerati) | |
# Date: May 14 2015 | |
# | |
# MSBuildPath: Path to where your MSBuild.exe file resides | |
# Projects: Array of Project/Solution files | |
# CleanDebug: Switch to clean build in debug mode | |
# CleanRelease: Switch to clean build int release mode | |
# | |
# Example: | |
# > .\CleanMSBuilds.ps1 -MSBuildPath path\to\msbuild.exe -Projects Example1.sln, Example2.sln -CleanDebug -CleanRelease | |
########################################################################### | |
param ( | |
[Parameter(Mandatory=$true)] | |
[string] $MSBuildPath, | |
[Parameter(Mandatory=$true)] | |
[string[]] $Projects, | |
[switch] $CleanDebug, | |
[switch] $CleanRelease | |
) | |
function Clean-Build($project, $config) { | |
$command = "$MSBuildPath $config /t:Clean $project" | |
Write-Host "Executing: $command" | |
cmd /c "$command" | |
if (! $?) { | |
throw "Clean of '$project' failed." | |
} | |
} | |
if (!(Test-Path $MSBuildPath)) { | |
Write-Error "Cannot find MSBuild at '$MSBuildPath'" | |
} | |
foreach ($project in $Projects) { | |
if (!(Test-Path $project)) { | |
Write-Error "Cannot find project/solution at '$project'" | |
} | |
} | |
Write-Host "Cleaning Projects/Solutions:" | |
foreach ($project in $Projects) { | |
Write-Host " - $project" | |
} | |
foreach ($project in $Projects) { | |
if ($CleanDebug.IsPresent) { | |
Clean-Build $project '/p:Configuration=Debug' | |
} | |
if ($CleanRelease.IsPresent) { | |
Clean-Build $project '/p:Configuration=Release' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment