-
Notifications
You must be signed in to change notification settings - Fork 1
/
Start-Build.psm1
109 lines (97 loc) · 3.51 KB
/
Start-Build.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function Invoke-Compile{
<#
.SYNOPSIS
Performs an msbuild compilation of the supplied Visual Studio solution (.sln) or project (.csproj|.vbproj) files.
.DESCRIPTION
Performs an msbuild compilation of the supplied Visual Studio solution (.sln) or project (.csproj|.vbproj) files.
.NOTES
Author: Lloyd Holman
Requirements: Copy this module to any location found in $env:PSModulePath
.PARAMETER msbuildPath
Optional. The full path to the msbuild.exe to compile with. Defaults to "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
.PARAMETER configMode
Optional. The config mode to build the solution in
.PARAMETER solutionFiles
Required.
.EXAMPLE
Import-Module Start-Build
Import the module
.EXAMPLE
Get-Command -Module Start-Build
List available functions
.EXAMPLE
Invoke-Compile
Execute the module
#>
[cmdletbinding()]
Param(
[Parameter(
Position = 0,
Mandatory = $False )]
[string]$msbuildPath = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe",
[Parameter(
Position = 1,
Mandatory = $False )]
[string]$configMode = "Release",
[Parameter(
Position = 2,
Mandatory = $True )]
[array]$solutionFiles,
[Parameter(
Position = 3,
Mandatory = $False )]
[string]$buildCounter = "0",
[Parameter(
Position = 4,
Mandatory = $False )]
[string]$gitPath
)
Begin {
$DebugPreference = "Continue"
}
Process {
if($configMode -ne "Debug" -or $configMode -ne "Release")
{
Write-Host "Unknown configMode $configMode supplied. Valid values are 'Debug' or 'Release', changing to default 'Release'"
$configMode = "Release"
}
Write-Host "configMode : $configMode"
$basePath = Resolve-Path .
$baseModulePath = "$basePath\lib\powershell\modules"
$major = 0
$minor = 1
foreach($solutionFile in $solutionFiles)
{
Try{
#Does what msbuild/VS can't do consistently. Aggressively and recursively deletes all /obj and /bin folders from the build path as well as the \BuildOutput folder
Import-Module "$baseModulePath\Remove-FoldersRecursively.psm1"
Remove-FoldersRecursively
Remove-Module Remove-FoldersRecursively
#Set build number
Import-Module "$baseModulePath\Set-BuildNumberWithGitCommitDetail.psm1"
$assemblyInformationalVersion = Set-BuildNumberWithGitCommitDetail -major $major -minor $minor -buildCounter $buildCounter -gitPath $gitPath
Remove-Module Set-BuildNumberWithGitCommitDetail
#Compile
Write-Host "Building solution: $solutionFile in $configMode mode"
& $msbuildPath $solutionFile /t:ReBuild /t:Clean /p:Configuration=$configMode /p:PlatformTarget=AnyCPU /m
#Run Unit Tests
Import-Module "$baseModulePath\Invoke-NUnitTestsForProject.psm1"
Invoke-NUnitTestsForProject -projectPath "Web\Femah.Examples.Additionator.Core.Tests\BuildOutput\Femah.Examples.Additionator.Core.Tests.dll"
Remove-Module Invoke-NUnitTestsForProject
}
Catch [Exception]
{
throw "Error building: $solutionFile. `r`n $_.Exception.ToString()"
}
Finally
{
Write-Host "Undoing AssemblyInfo.cs file changes"
Import-Module "$baseModulePath\Undo-GitFileModifications.psm1"
Undo-GitFileModifications -fileName AssemblyInfo.cs -gitPath $gitPath
Remove-Module Undo-GitFileModifications
}
#Allows us to trigger TeamCity to begin to publish artifacts
#Write-Output "##teamcity[publishArtifacts '**/*.* => Release/']"
}
}
}