build-new.ps1 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
  2. $configuration = "Release"
  3. $nuspecDir = Join-Path $scriptPath "NuSpecs"
  4. $isAppVeyor = Test-Path -Path env:\APPVEYOR
  5. if (!(Test-Path .\nuget.exe)) {
  6. wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
  7. }
  8. $msbuild = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"
  9. # TODO: if not found, bail out
  10. $msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
  11. # get version
  12. .\nuget.exe install -excludeversion gitversion.commandline -outputdirectory packages
  13. .\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
  14. $versionObj = .\packages\gitversion.commandline\tools\gitversion.exe | ConvertFrom-Json
  15. $version = $versionObj.MajorMinorPatch
  16. $tag = $versionObj.PreReleaseLabel
  17. $preRelNum = $versionObj.CommitsSinceVersionSourcePadded
  18. if($tag -ne ""){
  19. $version = "$version-$tag-$preRelNum"
  20. }
  21. Write-Host "Version: $version"
  22. Write-Host "Restoring packages" -Foreground Green
  23. dotnet restore $scriptPath | out-null
  24. #need to ensure core is built first due to bad dependency order determination by dotnet build
  25. $coreDir = gci $scriptPath -Directory | where-object {$_.Name -eq "System.Reactive.Core"} | Select -First 1
  26. dotnet build -c "$configuration" $coreDir.FullName
  27. Write-Host "Building projects" -Foreground Green
  28. $projects = gci $scriptPath -Directory `
  29. | Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
  30. foreach ($project in $projects) {
  31. dotnet build -c "$configuration" $project.FullName
  32. if ($LastExitCode -ne 0) {
  33. Write-Host "Error building project $project" -Foreground Red
  34. if($isAppVeyor) {
  35. $host.SetShouldExit($LastExitCode)
  36. }
  37. }
  38. }
  39. Write-Host "Building Packages" -Foreground Green
  40. $nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
  41. New-Item -ItemType Directory -Force -Path .\artifacts
  42. foreach ($nuspec in $nuspecs)
  43. {
  44. $symbolSwitch = "-symbols"
  45. # nuget will error if we pass -symbols to the meta-package
  46. if($nuSpec -like "*\System.Reactive.nuspec")
  47. {
  48. $symbolSwitch = ""
  49. }
  50. .\nuget pack $nuspec $symbolSwitch -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.12 -outputdirectory .\artifacts
  51. if ($LastExitCode -ne 0) {
  52. Write-Host "Error packing NuGet $nuspec" -Foreground Red
  53. if($isAppVeyor) {
  54. $host.SetShouldExit($LastExitCode)
  55. }
  56. }
  57. }
  58. Write-Host "Running tests" -Foreground Green
  59. $testDirectory = Join-Path $scriptPath "Tests.System.Reactive"
  60. dotnet test $testDirectory -c "$configuration"
  61. if ($LastExitCode -ne 0) {
  62. Write-Host "Error with tests" -Foreground Red
  63. if($isAppVeyor) {
  64. $host.SetShouldExit($LastExitCode)
  65. }
  66. }
  67. Write-Host "Reverting AssemblyInfo's" -Foreground Green
  68. gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ }