This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
/
build.ps1
137 lines (101 loc) · 3.76 KB
/
build.ps1
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
[CmdletBinding()] # Needed to support -Verbose
param(
[Parameter(Position = 0, Mandatory=$true)]
[ValidateSet("Release", "Debug")]
[string]$Configuration,
[Parameter(Position = 1, Mandatory=$true)]
[ValidateSet("AnyCPU", "x86", "x64")]
[string]$Platform,
[Parameter(Position = 2)]
[ValidateSet("quiet", "minimal", "normal", "diagnostic")]
[string]$Verbosity = "normal",
[switch]$RunTests
)
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
function Invoke-Tests() {
Write-Host "Running tests"
$testFolder = $(Resolve-Path $([IO.Path]::Combine($root, "tests"))).Path
$testResults = [IO.Path]::Combine($root, "TestResults")
if (!(Test-Path $testFolder)) {
Write-Error "Could not find test folder [$testFolder]"
return -1
}
if (!(Test-Path $testResults)) {
Write-Host "Creating $testResults folder..."
New-Item $testResults -ItemType Directory | Out-Null
}
dotnet --version
foreach ($test in $(Get-ChildItem $testFolder | ? { $_.PsIsContainer })) {
$csprojs = Get-ChildItem $test.FullName -Recurse | ? { $_.Extension -eq ".csproj" }
foreach ($proj in $csprojs) {
$trx = "$($proj.BaseName).$(Get-Date -Format "yyyy-MM-dd.hh_mm_ss").trx"
$fullpath = Join-Path $testResults $trx
Write-Host "Testing $($proj.Name). Output: $trx"
dotnet test "$($proj.FullName)" --configuration $Configuration --logger "trx;LogFileName=$fullpath" --no-build
}
}
}
function Set-DevEnvironment {
Write-Host "Getting msbuild"
$msbuild = "msbuild"
if (Get-Command $msbuild -ErrorAction SilentlyContinue)
{
Write-Host "$msbuild is already available"
return
}
$microsoftVisualStudio = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017"
if (Test-Path $microsoftVisualStudio) {
$installations = Get-ChildItem $microsoftVisualStudio | ? { $_.PsIsContainer }
foreach ($installation in $installations) {
$path = Join-Path $installation.FullName "Common7\Tools\"
Write-Host $path
if (Test-Path $path) {
$commonToolsPath = $path
break
}
}
} else {
Write-Error "Could not locate: $microsoftVisualStudio. Pass path to $VsDevCmdBat using parameter -VsDevCmdPath."
}
if ([string]::IsNullOrEmpty($commonToolsPath)) {
Write-Error "Could not find Common Tools for Visual Studio"
}
$devEnv = Join-Path $commonToolsPath "VSDevCmd.bat"
if (!(Test-Path $devEnv)) {
Write-Error "Could not find VsDevCmd.bat"
}
$output = cmd /c "`"$devEnv`" & set"
foreach ($line in $output)
{
if ($line -match "(?<key>.*?)=(?<value>.*)") {
$key = $matches["key"]
$value = $matches["value"]
Write-Verbose("$key=$value")
Set-Item "ENV:\$key" -Value "$value" -Force
}
}
if (Get-Command $msbuild -ErrorAction SilentlyContinue)
{
Write-Host "Added $msbuild to path"
return
}
Write-Error "Could not find $msbuild"
}
Set-DevEnvironment
# Show the MSBuild version for failure investigations
msbuild /version
$binFolder = [IO.Path]::Combine("bin", $Configuration)
New-Item $binFolder -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
& "$root\init.ps1"
# PortabilityTools.sln understands "Any CPU" not "AnyCPU"
$PlatformToUse = $Platform
if ($Platform -eq "AnyCPU") {
$PlatformToUse = "Any CPU"
}
Push-Location $root
& msbuild PortabilityTools.sln "/t:restore;build;pack" /p:Configuration=$Configuration /p:Platform="$PlatformToUse" /nologo /m /v:m /nr:false "/bl:$binFolder\msbuild.binlog"
Pop-Location
if ($RunTests) {
Invoke-Tests
}