1- function Install-Dnvm
1+ function Install-Dotnet
22{
3- & where.exe dnvm 2>&1 | Out-Null
4- if (($LASTEXITCODE -ne 0 ) -Or ((Test-Path Env:\APPVEYOR) -eq $true ))
3+ & where.exe dotnet 2>&1 | Out-Null
4+
5+ if (($LASTEXITCODE -ne 0 ) -Or ((Test-Path Env:\APPVEYOR) -eq $true ))
6+ {
7+ Write-Host " Dotnet CLI not found - downloading latest version"
8+
9+ # Prepare the dotnet CLI folder
10+ $env: DOTNET_INSTALL_DIR = " $ ( Convert-Path " $PSScriptRoot " ) \.dotnet\win7-x64"
11+ if (! (Test-Path $env: DOTNET_INSTALL_DIR ))
512 {
6- Write-Host " DNVM not found "
7- & { $Branch = ' dev ' ;iex (( new-object net.webclient).DownloadString( ' https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1 ' )) }
13+ mkdir $ env: DOTNET_INSTALL_DIR | Out-Null
14+ }
815
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- }
16+ # Download the dotnet CLI install script
17+ if (! (Test-Path .\dotnet\install.ps1))
18+ {
19+ Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" - OutFile " .\.dotnet\dotnet-install.ps1"
1820 }
21+
22+ # Run the dotnet CLI install
23+ & .\.dotnet\dotnet- install.ps1
24+
25+ # Add the dotnet folder path to the process. This gets skipped
26+ # by Install-DotNetCli if it's already installed.
27+ Remove-PathVariable $env: DOTNET_INSTALL_DIR
28+ $env: PATH = " $env: DOTNET_INSTALL_DIR ;$env: PATH "
29+
30+ }
1931}
2032
21- function Get-DnxVersion
33+ function Remove-PathVariable
2234{
23- $globalJson = join-path $PSScriptRoot " global.json"
24- $jsonData = Get-Content - Path $globalJson - Raw | ConvertFrom-JSON
25- return $jsonData.sdk.version
35+ [cmdletbinding ()]
36+ param ([string ] $VariableToRemove )
37+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " User" )
38+ $newItems = $path.Split (' ;' ) | Where-Object { $_.ToString () -inotlike $VariableToRemove }
39+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " User" )
40+ $path = [Environment ]::GetEnvironmentVariable(" PATH" , " Process" )
41+ $newItems = $path.Split (' ;' ) | Where-Object { $_.ToString () -inotlike $VariableToRemove }
42+ [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " Process" )
2643}
2744
2845function Restore-Packages
2946{
3047 param ([string ] $DirectoryName )
31- & dnu restore -- quiet (" "" " + $DirectoryName + " "" " )
32- }
33-
34- function Pack-Projects
35- {
36- param ([string ] $DirectoryName , [string ] $Configuration )
37- & dnu pack -- quiet (" "" " + $DirectoryName + " "" " ) -- configuration $Configuration -- out .\artifacts\packages; if ($LASTEXITCODE -ne 0 ) { exit 2 }
48+ & dotnet restore - v Warning (" "" " + $DirectoryName + " "" " )
3849}
3950
4051function Test-Projects
4152{
42- & dnx test; if ($LASTEXITCODE -ne 0 ) { exit 3 }
43- }
44-
45- function Remove-PathVariable
46- {
47- param ([string ] $VariableToRemove )
48- $path = [Environment ]::GetEnvironmentVariable(" PATH" , " User" )
49- $newItems = $path.Split (' ;' ) | Where-Object { $_.ToString () -inotlike $VariableToRemove }
50- [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " User" )
51- $path = [Environment ]::GetEnvironmentVariable(" PATH" , " Process" )
52- $newItems = $path.Split (' ;' ) | Where-Object { $_.ToString () -inotlike $VariableToRemove }
53- [Environment ]::SetEnvironmentVariable(" PATH" , [System.String ]::Join(' ;' , $newItems ), " Process" )
53+ & dotnet test - c Release;
54+ if ($LASTEXITCODE -ne 0 )
55+ {
56+ exit 3
57+ }
5458}
5559
5660# #######################
@@ -59,55 +63,19 @@ function Remove-PathVariable
5963
6064Push-Location $PSScriptRoot
6165
62- $dnxVersion = Get-DnxVersion
63-
64- if (! $env: CONFIGURATION )
65- {
66- $env: CONFIGURATION = " Release"
67- }
68-
69- # Clean
70- if (Test-Path .\artifacts) { Remove-Item .\artifacts - Force - Recurse }
71-
72- # Remove the installed DNVM from the path and force use of
73- # per-user DNVM (which we can upgrade as needed without admin permissions)
74- Remove-PathVariable " *Program Files\Microsoft DNX\DNVM*"
75-
76- # Make sure per-user DNVM is installed
77- Install-Dnvm
78-
79- # Install DNX
80- dnvm install $dnxVersion - r CoreCLR - NoNative
81- dnvm install $dnxVersion - r CLR - NoNative
82-
83- # Start with regular CLR
84- dnvm use $dnxVersion - r CLR
66+ # Install Dotnet CLI
67+ Install-Dotnet
8568
8669# Package restore
70+ Write-Host " Running package restore"
8771Get-ChildItem - Path . - Filter * .xproj - Recurse | ForEach-Object { Restore-Packages $_.DirectoryName }
8872
89- # Set build number
90- $env: DNX_BUILD_VERSION = @ { $true = $env: APPVEYOR_BUILD_NUMBER ; $false = 1 }[$env: APPVEYOR_BUILD_NUMBER -ne $NULL ];
91- Write-Host " Build number: " $env: DNX_BUILD_VERSION
92-
93- # Package
94- Get-ChildItem - Path .\src - Filter * .xproj - Recurse | ForEach-Object { Pack- Projects $_.DirectoryName $env: CONFIGURATION }
95-
96- # Test
73+ # Tests
74+ Write-Host " Running tests"
9775Get-ChildItem - Path .\test - Filter * .xproj - Exclude Nancy.ViewEngines.Razor.Tests.Models.xproj - Recurse | ForEach-Object {
9876 Push-Location $_.DirectoryName
99- Test-Projects $_ .DirectoryName
77+ Test-Projects
10078 Pop-Location
101- }
102-
103- # Switch to Core CLR
104- # dnvm use $dnxVersion -r CoreCLR
105-
106- # Test again
107- # Get-ChildItem -Path .\test -Filter *Tests.xproj -Recurse | ForEach-Object {
108- # Push-Location $_.DirectoryName
109- # Test-Projects $_.DirectoryName
110- # Pop-Location
111- # }
79+ }
11280
11381Pop-Location
0 commit comments