forked from khellang/Scrutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
86 lines (69 loc) · 2.58 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
function Install-Dotnet
{
& where.exe dotnet 2>&1 | Out-Null
if(($LASTEXITCODE -ne 0) -Or ((Test-Path Env:\APPVEYOR) -eq $true))
{
Write-Host "Dotnet CLI not found - downloading latest version"
# Prepare the dotnet CLI folder
$env:DOTNET_INSTALL_DIR="$(Convert-Path "$PSScriptRoot")\.dotnet\win7-x64"
if (!(Test-Path $env:DOTNET_INSTALL_DIR))
{
mkdir $env:DOTNET_INSTALL_DIR | Out-Null
}
# Download the dotnet CLI install script
if (!(Test-Path .\dotnet\install.ps1))
{
Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.ps1" -OutFile ".\.dotnet\dotnet-install.ps1"
}
# Skip all the extra work
$env:DOTNET_CLI_TELEMETRY_OPTOUT = "1"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
# Run the dotnet CLI install
& .\.dotnet\dotnet-install.ps1 -Version "2.1.4"
# Add the dotnet folder path to the process.
Remove-PathVariable $env:DOTNET_INSTALL_DIR
$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
}
}
function Remove-PathVariable
{
[cmdletbinding()]
param([string] $VariableToRemove)
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}
function Restore-Packages
{
param([string] $DirectoryName)
& dotnet restore -v minimal ("""" + $DirectoryName + """")
if($LASTEXITCODE -ne 0) { exit 1 }
}
function Test-Project
{
param([string] $ProjectPath)
& dotnet test -v minimal -c Release ("""" + $ProjectPath + """")
if($LASTEXITCODE -ne 0) { exit 1 }
}
function Pack-Project
{
param([string] $ProjectPath)
& dotnet pack -v minimal -c Release --output packages ("""" + $ProjectPath + """")
if($LASTEXITCODE -ne 0) { exit 1 }
}
########################
# THE BUILD!
########################
Push-Location $PSScriptRoot
# Install Dotnet CLI
Install-Dotnet
# Package restore
Get-ChildItem -Path . -Filter *.csproj -Recurse | ForEach-Object { Restore-Packages $_.DirectoryName }
# Tests
Get-ChildItem -Path .\test -Filter *.csproj -Recurse | ForEach-Object { Test-Project $_.FullName }
# Pack
Get-ChildItem -Path .\src -Filter *.csproj -Recurse | ForEach-Object { Pack-Project $_.FullName }
Pop-Location