summaryrefslogtreecommitdiffstats
path: root/default.ps1
blob: 7545dc188994bd590e1cb3102777858e493a9990 (plain)
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
# OATH.NET Psake build script

## Primary Build Tasks ##

Task Build      -Depend BuildSolution           -Description "Builds the project"
Task Test       -Depend Build, TestSolution     -Description "Runs all unit tests"
Task Package    -Depend Test, CreateNuPkg       -Description "Creates the NuGet package"
Task Clean      -Depend CleanSolution           -Description "Deletes all build artifacts"
Task Default    -Depend Test


## Build Process ##

Framework "4.0"

Properties {
    if (!$Configuration) { $Configuration = "Release" }

    $workingTree = Resolve-Path .
    $solution   = "$workingTree\OATH.Net.sln"
    $nuspec     = "$workingTree\OATH.Net.nuspec"

    $nunit = "$workingTree\packages\NUnit.Runners.2.6.3\tools\nunit-console.exe"
    $testAssembly = "$workingTree\OATH.Net.Test\bin\$Configuration\OATH.Net.Test.dll"

    $nuget = GetNuGetPath
}

Task RestoreNuGetPackages {
    Status "Restoring NuGet packages"
    Exec { & $nuget restore $solution -NonInteractive }
}

Task BuildSolution -Depend RestoreNuGetPackages {
    Exec { msbuild /target:build $solution /p:Configuration=$configuration }
}

Task TestSolution {
    Exec { & $nunit "$testAssembly" /framework=net-4.0 /nologo }
}

Task CleanSolution {
    Exec { msbuild /target:clean $solution /p:Configuration=$Configuration }
    del -ErrorAction Ignore *.nupkg
    del -ErrorAction Ignore TestResult.xml
}

Task CreateNuPkg {
    Exec { & $nuget pack $nuspec }
}


## Helpers ##

function GetNuGetPath {
    if (Get-Command "nuget" -ErrorAction SilentlyContinue) {
        $nuget = "nuget.exe"
    } else {
        $temp = [System.IO.Path]::GetTempPath()
        $nuget = "${temp}nuget.exe"
        if (!(Test-Path $nuget)) {
            Status "Downloading nuget.exe to $nuget"
            (New-Object System.Net.WebClient).DownloadFile("http://nuget.org/nuget.exe", $nuget)
        }
    }
    return $nuget
}

FormatTaskName {
    param($taskName)
    Write-Output ("=" * 72)
    Write-Output "Running task '$taskName'"
    Write-Output ("=" * 72)
}

function Status {
    param($text)
    Write-Output ("-" * 72)
    Write-Output " $text"
    Write-Output ("-" * 72)
}