build-new.ps1 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 version
  11. .\nuget.exe install -excludeversion -pre gitversion.commandline -outputdirectory packages
  12. .\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
  13. $versionObj = .\packages\gitversion.commandline\tools\gitversion.exe | ConvertFrom-Json
  14. $version = $versionObj.MajorMinorPatch
  15. $tag = $versionObj.PreReleaseLabel
  16. $preRelNum = $versionObj.CommitsSinceVersionSourcePadded
  17. if($tag -ne ""){
  18. $version = "$version-$tag-$preRelNum"
  19. }
  20. Write-Host "Version: $version"
  21. # Get Reference Generator
  22. .\nuget.exe install -excludeversion -pre NuSpec.ReferenceGenerator -outputdirectory packages
  23. Write-Host "Restoring packages" -Foreground Green
  24. dotnet restore $scriptPath | out-null
  25. Write-Host "Building projects" -Foreground Green
  26. $projects = gci $scriptPath -Directory `
  27. | Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
  28. foreach ($project in $projects) {
  29. dotnet build -c "$configuration" $project.FullName
  30. $ns = Join-Path $nuSpecDir "$($project.Name).nuspec"
  31. if(Test-Path $ns)
  32. {
  33. Write-Host "Invoking RefGen on $ns"
  34. $baseDir = Join-Path $project.FullName "bin" | join-path -ChildPath "$configuration"
  35. $projJson = Join-Path $project.FullName "project.json"
  36. Write-Host RefGen.exe generate-cross "-p" `"$projJson`" "-d" `"$baseDir`" "-l" `"$($project.Name).dll`" "-n" `"$ns`"
  37. .\packages\nuspec.referencegenerator\tools\RefGen.exe generate-cross -p "$projJson" -d "$baseDir" -l "$($project.Name).dll" -n "$ns"
  38. }
  39. }
  40. Write-Host "Building Packages" -Foreground Green
  41. $nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
  42. New-Item -ItemType Directory -Force -Path .\artifacts
  43. foreach ($nuspec in $nuspecs) {
  44. .\nuget pack $nuspec -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.8.6 -outputdirectory .\artifacts
  45. }
  46. Write-Host "Running tests" -Foreground Green
  47. $testDirectory = Join-Path $scriptPath "Tests"
  48. dotnet test $testDirectory -c $configuration