build-new.ps1 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
  2. $configuration = "Release"
  3. $nuspecDir = Join-Path $scriptPath "NuSpecs"
  4. if (!(Test-Path .\nuget.exe)) {
  5. wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
  6. }
  7. $msbuild = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"
  8. # TODO: if not found, bail out
  9. $msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
  10. # get tools
  11. .\nuget.exe install -excludeversion -pre gitversion.commandline -outputdirectory packages
  12. #update version
  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. # Get Reference Generator
  23. .\nuget.exe install -excludeversion -pre NuSpec.ReferenceGenerator -outputdirectory packages
  24. Write-Host "Restoring packages" -Foreground Green
  25. dotnet restore $scriptPath | out-null
  26. Write-Host "Building projects" -Foreground Green
  27. $projects = gci $scriptPath -Directory `
  28. | Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
  29. foreach ($project in $projects) {
  30. dotnet build -c "$configuration" $project.FullName
  31. $ns = Join-Path $nuSpecDir "$($project.Name).nuspec"
  32. if(Test-Path $ns)
  33. {
  34. Write-Host "Invoking RefGen on $ns"
  35. $baseDir = Join-Path $project.FullName "bin" | join-path -ChildPath "$configuration"
  36. $projJson = Join-Path $project.FullName "project.json"
  37. Write-Host RefGen.exe generate-cross "-p" `"$projJson`" "-d" `"$baseDir`" "-l" `"$($project.Name).dll`" "-n" `"$ns`"
  38. .\packages\nuspec.referencegenerator\tools\RefGen.exe generate-cross -p "$projJson" -d "$baseDir" -l "$($project.Name).dll" -n "$ns"
  39. }
  40. }
  41. Write-Host "Building Packages" -Foreground Green
  42. $nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
  43. New-Item -ItemType Directory -Force -Path .\artifacts
  44. foreach ($nuspec in $nuspecs) {
  45. .\nuget pack $nuspec -symbols -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.8.6 -outputdirectory .\artifacts
  46. }
  47. Write-Host "Running tests" -Foreground Green
  48. $testDirectory = Join-Path $scriptPath "Tests"
  49. dotnet test $testDirectory -c $configuration