|
| 1 | +function Install-Dnvm |
| 2 | +{ |
| 3 | + & where.exe dnvm 2>&1 | Out-Null |
| 4 | + if(($LASTEXITCODE -ne 0) -Or ((Test-Path Env:\APPVEYOR) -eq $true)) |
| 5 | + { |
| 6 | + Write-Host "DNVM not found" |
| 7 | + &{$Branch='dev';iex ((New-Object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))} |
| 8 | + |
| 9 | + # Normally this happens automatically during install but AppVeyor has |
| 10 | + # an issue where you may need to manually re-run setup from within this process. |
| 11 | + if($env:DNX_HOME -eq $NULL) |
| 12 | + { |
| 13 | + Write-Host "Initial DNVM environment setup failed; running manual setup" |
| 14 | + $tempDnvmPath = Join-Path $env:TEMP "dnvminstall" |
| 15 | + $dnvmSetupCmdPath = Join-Path $tempDnvmPath "dnvm.ps1" |
| 16 | + & $dnvmSetupCmdPath setup |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +function Get-DnxVersion |
| 22 | +{ |
| 23 | + $globalJson = Join-Path $PSScriptRoot "global.json" |
| 24 | + $jsonData = Get-Content -Path $globalJson -Raw | ConvertFrom-JSON |
| 25 | + return $jsonData.sdk.version |
| 26 | +} |
| 27 | + |
| 28 | +function Restore-Packages |
| 29 | +{ |
| 30 | + param([string] $DirectoryName) |
| 31 | + & dnu restore ("""" + $DirectoryName + """") |
| 32 | +} |
| 33 | + |
| 34 | +function Build-Projects |
| 35 | +{ |
| 36 | + param([string] $DirectoryName) |
| 37 | + & dnu build ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\testbin; if($LASTEXITCODE -ne 0) { exit 1 } |
| 38 | + & dnu pack ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\packages; if($LASTEXITCODE -ne 0) { exit 1 } |
| 39 | +} |
| 40 | + |
| 41 | +function Build-TestProjects |
| 42 | +{ |
| 43 | + param([string] $DirectoryName) |
| 44 | + & dnu build ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\testbin; if($LASTEXITCODE -ne 0) { exit 1 } |
| 45 | +} |
| 46 | + |
| 47 | +function Test-Projects |
| 48 | +{ |
| 49 | + param([string] $DirectoryName) |
| 50 | + & dnx -p ("""" + $DirectoryName + """") test; if($LASTEXITCODE -ne 0) { exit 2 } |
| 51 | +} |
| 52 | + |
| 53 | +function Remove-PathVariable |
| 54 | +{ |
| 55 | + param([string] $VariableToRemove) |
| 56 | + $path = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 57 | + $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
| 58 | + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") |
| 59 | + $path = [Environment]::GetEnvironmentVariable("PATH", "Process") |
| 60 | + $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
| 61 | + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") |
| 62 | +} |
| 63 | + |
| 64 | +Push-Location $PSScriptRoot |
| 65 | + |
| 66 | +$dnxVersion = Get-DnxVersion |
| 67 | + |
| 68 | +# Clean |
| 69 | +if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } |
| 70 | + |
| 71 | +# Remove the installed DNVM from the path and force use of |
| 72 | +# per-user DNVM (which we can upgrade as needed without admin permissions) |
| 73 | +Remove-PathVariable "*Program Files\Microsoft DNX\DNVM*" |
| 74 | + |
| 75 | +# Make sure per-user DNVM is installed |
| 76 | +Install-Dnvm |
| 77 | + |
| 78 | +# Install DNX |
| 79 | +dnvm install $dnxVersion -r CoreCLR -NoNative |
| 80 | +dnvm install $dnxVersion -r CLR -NoNative |
| 81 | +dnvm use $dnxVersion -r CLR |
| 82 | + |
| 83 | +# Package restore |
| 84 | +Get-ChildItem -Path . -Filter *.xproj -Recurse | ForEach-Object { Restore-Packages $_.DirectoryName } |
| 85 | + |
| 86 | +# Set build number |
| 87 | +$env:DNX_BUILD_VERSION = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
| 88 | +Write-Host "Build number: " $env:DNX_BUILD_VERSION |
| 89 | + |
| 90 | +# Build/package |
| 91 | +Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Build-Projects $_.DirectoryName } |
| 92 | +Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Build-TestProjects $_.DirectoryName } |
| 93 | + |
| 94 | +# Test |
| 95 | +Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName } |
| 96 | + |
| 97 | +# Switch to Core CLR |
| 98 | +dnvm use $dnxVersion -r CoreCLR |
| 99 | + |
| 100 | +# Test again |
| 101 | +Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName } |
| 102 | + |
| 103 | +Pop-Location |
0 commit comments