forked from justeattakeaway/AwsWatchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotnetfunctions.ps1
76 lines (61 loc) · 2.82 KB
/
dotnetfunctions.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
# These make CI builds faster
$env:DOTNET_MULTILEVEL_LOOKUP = "0"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
$env:NUGET_XMLDOC_MODE = "skip"
# Required since 2.1.300 to get console output from xunit for failed tests
$env:MSBUILDENSURESTDOUTFORTASKPROCESSES=1
$solutionPath = Split-Path $MyInvocation.MyCommand.Definition
$sdkFile = Join-Path $solutionPath "global.json"
$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version
if ($env:TEAMCITY_VERSION -ne $null) {
$BuildPackage = $true
$OutputPath = Join-Path "$(Convert-Path "$PSScriptRoot")" "out"
$VersionPrefix = $env:BUILD_NUMBER
if ($env:TEAMCITY_IS_DEFAULT_BRANCH -eq "false") {
$VersionSuffix = "beta"
}
}
elseif ($OutputPath -eq "") {
$OutputPath = Join-Path "$(Convert-Path "$PSScriptRoot")" "artifacts"
}
$installDotNetSdk = $false;
if (((Get-Command "dotnet.exe" -ErrorAction SilentlyContinue) -eq $null) -and ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -eq $null)) {
Write-Host "The .NET Core SDK is not installed."
$installDotNetSdk = $true
}
else {
Try {
$installedDotNetVersion = (dotnet --version 2>&1 | Out-String).Trim()
}
Catch {
$installedDotNetVersion = "?"
}
if ($installedDotNetVersion -ne $dotnetVersion) {
Write-Host "The required version of the .NET Core SDK is not installed. Expected $dotnetVersion."
$installDotNetSdk = $true
}
}
if ($installDotNetSdk -eq $true) {
Write-Host "Installing the .NET Core SDK $dotnetVersion."
$env:DOTNET_INSTALL_DIR = Join-Path "$(Convert-Path "$PSScriptRoot")" ".dotnetcli"
$env:MSBuildSDKsPath = Join-Path $env:DOTNET_INSTALL_DIR "sdk\$dotnetVersion\Sdks"
if (($env:TEAMCITY_VERSION -ne $null) -or (!(Test-Path $env:DOTNET_INSTALL_DIR))) {
mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
$installScript = Join-Path $env:DOTNET_INSTALL_DIR "install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12"
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile $installScript -UseBasicParsing
& $installScript -Version "$dotnetVersion" -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath
}
$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
$dotnet = Join-Path "$env:DOTNET_INSTALL_DIR" "dotnet.exe"
} else {
$dotnet = "dotnet"
Write-Host "The required version of the .NET Core SDK, $dotnetVersion is already installed."
}
function DotNetTest {
param([string] $Project)
& $dotnet test $Project --output $OutputPath --logger:"console;verbosity=normal" -- RunConfiguration.TestSessionTimeout=600000
if ($LASTEXITCODE -ne 0) {
throw "dotnet test failed with exit code $LASTEXITCODE"
}
}