|
1 | 1 | ########################
|
2 |
| -# FUNCTIONS |
| 2 | +# THE BUILD! |
3 | 3 | ########################
|
4 |
| -function Install-Dnvm |
5 |
| -{ |
6 |
| - & where.exe dnvm 2>&1 | Out-Null |
7 |
| - if(($LASTEXITCODE -ne 0) -Or ((Test-Path Env:\APPVEYOR) -eq $true)) |
8 |
| - { |
9 |
| - Write-Host "DNVM not found" |
10 |
| - &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))} |
11 |
| - |
12 |
| - # Normally this happens automatically during install but AppVeyor has |
13 |
| - # an issue where you may need to manually re-run setup from within this process. |
14 |
| - if($env:DNX_HOME -eq $NULL) |
15 |
| - { |
16 |
| - Write-Host "Initial DNVM environment setup failed; running manual setup" |
17 |
| - $tempDnvmPath = Join-Path $env:TEMP "dnvminstall" |
18 |
| - $dnvmSetupCmdPath = Join-Path $tempDnvmPath "dnvm.ps1" |
19 |
| - & $dnvmSetupCmdPath setup |
20 |
| - } |
21 |
| - } |
22 |
| -} |
| 4 | +Push-Location $PSScriptRoot |
23 | 5 |
|
24 |
| -function Get-DnxVersion |
| 6 | +function Invoke-DotNetBuild |
25 | 7 | {
|
26 |
| - $globalJson = join-path $PSScriptRoot "global.json" |
27 |
| - $jsonData = Get-Content -Path $globalJson -Raw | ConvertFrom-JSON |
28 |
| - return $jsonData.sdk.version |
| 8 | + [cmdletbinding()] |
| 9 | + param([string] $DirectoryName) |
| 10 | + & dotnet build ("""" + $DirectoryName + """") -c Release; if($LASTEXITCODE -ne 0) { exit 1 } |
29 | 11 | }
|
30 | 12 |
|
31 |
| -function Restore-Packages |
| 13 | +function Invoke-Tests |
32 | 14 | {
|
33 |
| - param([string] $DirectoryName) |
34 |
| - & dnu restore ("""" + $DirectoryName + """") |
| 15 | + [cmdletbinding()] |
| 16 | + param([string] $DirectoryName) |
| 17 | + & dotnet test ("""" + $DirectoryName + """") -c Release; if($LASTEXITCODE -ne 0) { exit 1 } |
35 | 18 | }
|
36 | 19 |
|
37 |
| -function Build-Project |
| 20 | +function Invoke-DotNetPack |
38 | 21 | {
|
39 |
| - param([string] $DirectoryName) |
40 |
| - & dnu build ("""" + $DirectoryName + """") --configuration Release; if($LASTEXITCODE -ne 0) { exit 1 } |
| 22 | + [cmdletbinding()] |
| 23 | + param([string] $DirectoryName) |
| 24 | + & dotnet pack ("""" + $DirectoryName + """") -c Release -o .\artifacts\packages; if($LASTEXITCODE -ne 0) { exit 1 } |
41 | 25 | }
|
42 | 26 |
|
43 |
| -function Package-Project |
| 27 | +function Remove-PathVariable |
44 | 28 | {
|
45 |
| - param([string] $DirectoryName) |
46 |
| - & dnu pack ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\packages; if($LASTEXITCODE -ne 0) { exit 1 } |
| 29 | + [cmdletbinding()] |
| 30 | + param([string] $VariableToRemove) |
| 31 | + $path = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 32 | + $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
| 33 | + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") |
| 34 | + $path = [Environment]::GetEnvironmentVariable("PATH", "Process") |
| 35 | + $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
| 36 | + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") |
47 | 37 | }
|
48 | 38 |
|
49 |
| -function Publish-TestProject |
| 39 | +# Prepare the dotnet CLI folder |
| 40 | +$env:DOTNET_INSTALL_DIR="$(Convert-Path "$PSScriptRoot")\.dotnet\win7-x64" |
| 41 | +if (!(Test-Path $env:DOTNET_INSTALL_DIR)) |
50 | 42 | {
|
51 |
| - param([string] $DirectoryName, [int]$Index) |
52 |
| - |
53 |
| - # Publish to a numbered/indexed folder rather than the full test project name |
54 |
| - # because the package paths get long and start exceeding OS limitations. |
55 |
| - & dnu publish ("""" + $DirectoryName + """") --configuration Release --no-source --out .\artifacts\tests\$Index; if($LASTEXITCODE -ne 0) { exit 2 } |
| 43 | + mkdir $env:DOTNET_INSTALL_DIR | Out-Null |
56 | 44 | }
|
57 | 45 |
|
58 |
| -function Invoke-Tests |
| 46 | +# Download the dotnet CLI install script |
| 47 | +if (!(Test-Path .\dotnet\install.ps1)) |
59 | 48 | {
|
60 |
| - Get-ChildItem .\artifacts\tests -Filter test.cmd -Recurse | ForEach-Object { & $_.FullName; if($LASTEXITCODE -ne 0) { exit 3 } } |
| 49 | + Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\.dotnet\dotnet-install.ps1" |
61 | 50 | }
|
62 | 51 |
|
63 |
| -function Remove-PathVariable |
64 |
| -{ |
65 |
| - param([string] $VariableToRemove) |
66 |
| - $path = [Environment]::GetEnvironmentVariable("PATH", "User") |
67 |
| - $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
68 |
| - [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") |
69 |
| - $path = [Environment]::GetEnvironmentVariable("PATH", "Process") |
70 |
| - $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
71 |
| - [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") |
72 |
| -} |
| 52 | +# Run the dotnet CLI install |
| 53 | +& .\.dotnet\dotnet-install.ps1 |
73 | 54 |
|
74 |
| -######################## |
75 |
| -# THE BUILD! |
76 |
| -######################## |
77 |
| - |
78 |
| -Push-Location $PSScriptRoot |
| 55 | +# Add the dotnet folder path to the process. This gets skipped |
| 56 | +# by Install-DotNetCli if it's already installed. |
| 57 | +Remove-PathVariable $env:DOTNET_INSTALL_DIR |
| 58 | +$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH" |
79 | 59 |
|
80 |
| -$dnxVersion = Get-DnxVersion |
| 60 | +# Set build number |
| 61 | +$env:DOTNET_BUILD_VERSION = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1}[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
| 62 | +Write-Host "Build number:" $env:DOTNET_BUILD_VERSION |
81 | 63 |
|
82 | 64 | # Clean
|
83 |
| -if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } |
84 |
| - |
85 |
| -# Remove the installed DNVM from the path and force use of |
86 |
| -# per-user DNVM (which we can upgrade as needed without admin permissions) |
87 |
| -Remove-PathVariable "*Program Files\Microsoft DNX\DNVM*" |
88 |
| -Install-Dnvm |
89 |
| - |
90 |
| -# Install DNX |
91 |
| -dnvm update-self |
92 |
| -dnvm upgrade |
93 |
| - |
94 |
| -# Make sure these versions of DNX (for now) are installed |
95 |
| -dnvm install $dnxVersion -r clr -a x86 -NoNative |
96 |
| -dnvm install $dnxVersion -r clr -a x64 -NoNative |
97 |
| -dnvm install $dnxVersion -r coreclr -a x86 -NoNative |
98 |
| -dnvm install $dnxVersion -r coreclr -a x64 -NoNative |
99 |
| -dnvm use $dnxVersion -r clr |
100 |
| -dnvm list |
101 |
| -npm cache clean |
102 |
| -dnu restore |
| 65 | +if(Test-Path .\artifacts) |
| 66 | +{ |
| 67 | + Remove-Item .\artifacts -Force -Recurse |
| 68 | +} |
103 | 69 |
|
104 | 70 | # Package restore
|
105 |
| -Get-ChildItem -Path . -Filter *.xproj -Recurse | ForEach-Object { dnu restore ("""" + $_.DirectoryName + """") } |
106 |
| - |
107 |
| -# Set build number |
108 |
| -$env:DNX_BUILD_VERSION = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1}[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
109 |
| -Write-Host "Build number:" $env:DNX_BUILD_VERSION |
| 71 | +& dotnet restore |
110 | 72 |
|
111 | 73 | # Build/package
|
112 |
| -Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Package-Project $_.DirectoryName } |
113 |
| -# Get-ChildItem -Path .\samples -Filter *.xproj -Recurse | ForEach-Object { Build-Project $_.DirectoryName } |
114 |
| - |
115 |
| -# Publish tests so we can test without recompiling |
116 |
| -Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object -Begin { $TestIndex = 0 } -Process { Publish-TestProject -DirectoryName $_.DirectoryName -Index $TestIndex; $TestIndex++; } |
| 74 | +Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Invoke-DotNetPack $_.DirectoryName } |
| 75 | +Get-ChildItem -Path .\samples -Filter *.xproj -Recurse | ForEach-Object { Invoke-DotNetBuild $_.DirectoryName } |
117 | 76 |
|
118 |
| -# Test under CLR |
119 |
| -# Invoke-Tests |
| 77 | +# Test |
| 78 | +# Get-ChildItem -Path .\tests -Filter *.xproj -Recurse | ForEach-Object { Invoke-Tests $_.DirectoryName } |
120 | 79 |
|
121 |
| -# Switch to Core CLR |
122 |
| -#dnvm use $dnxVersion -r CoreCLR |
| 80 | +Pop-Location |
123 | 81 |
|
124 |
| -# Test under Core CLR |
125 |
| -#Invoke-Tests |
126 | 82 |
|
127 |
| -Pop-Location |
0 commit comments