002_library.ps1 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #**************************************************************************#
  2. #** QUADARAX DEPLOYMENT SCRIPTS **#
  3. #** File: 002_library.ps1 **#
  4. #** Description: PowerShell script library of elementary functions to **#
  5. #** work with QDS **#
  6. #** Version: 1.0. **#
  7. #** Updated: 24.7.2019 **#
  8. #**************************************************************************#
  9. # Rebuilds solution file, may calls CleanSolution
  10. Function RebuildSolution
  11. {
  12. param(
  13. # Solution file name with full path
  14. [string] $solutionFileName,
  15. # Build configuration Debug / Release
  16. [string] $configurationName = $buildCfgDebug,
  17. # Defines alternative output directory. If not defined, use default output locations depends on configuration
  18. [string] $alternativeOutputDirectory,
  19. # Defines if Clean will be called before build
  20. [bool] $cleanBeforeBuild = $false,
  21. # Defines if only show calling commands instead of executes them (just for debugging)
  22. [bool] $simulate = $false
  23. )
  24. $fileExists = Test-Path($solutionFileName)
  25. if ($fileExists -eq $false){
  26. Write-Error("Solution file '{0}' doesn't exists." -f $solutionFileName)
  27. Break
  28. }
  29. if (!$alternativeOutputDirectory){
  30. $alternativeOutputDirectory = ""
  31. }
  32. else{
  33. $alternativeOutputDirectory = " /p:OutputPath='{0}' " -f $alternativeOutputDirectory
  34. }
  35. Write-Host("**** BEGIN *** BUILDS SOLUTION/PROJECT : {0} ****" -f $solutionFileName) -ForegroundColor Yellow
  36. if ($cleanBeforeBuild -eq $true){
  37. CleanSolution $solutionFileName $configurationName $simulate
  38. }
  39. if ($simulate -eq $true){
  40. Write-Host "msbuild $solutionFileName /t:$buildTrgRebuild /p:VisualStudioVersion=15.0 /p:Configuration=$configurationName /m /clp:Summary /clp:ShowTimestamp $alternativeOutputDirectory" -ForegroundColor Cyan
  41. } else{
  42. msbuild $solutionFileName /t:$buildTrgRebuild /p:VisualStudioVersion=15.0 /p:Configuration=$configurationName /m /clp:Summary /clp:ShowTimestamp $alternativeOutputDirectory
  43. }
  44. Write-Host("**** END *** BUILDS SOLUTION/PROJECT : {0} ****" -f $solutionFileName) -ForegroundColor Yellow
  45. }
  46. # Cleans solution file
  47. Function CleanSolution
  48. {
  49. param(
  50. # Solution file name with full path
  51. [string] $solutionFileName,
  52. # Build configuration Debug / Release
  53. [string] $configurationName = $buildCfgDebug,
  54. # Defines if only show calling commands instead of executes them (just for debugging)
  55. [bool] $simulate = $false
  56. )
  57. $fileExists = Test-Path($solutionFileName)
  58. if ($fileExists -eq $false){
  59. Write-Error("Solution file '{0}' doesn't exists." -f $solutionFileName)
  60. Break
  61. }
  62. Write-Host("***** BEGIN *** CLEANS SOLUTION/PROJECT : {0} *****" -f $solutionFileName) -ForegroundColor DarkYellow
  63. if ($simulate -eq $true){
  64. Write-Host "msbuild $solutionFileName /t:$buildTrgClean /p:VisualStudioVersion=15.0 /p:Configuration=$configurationName /m" -ForegroundColor Cyan
  65. } else{
  66. msbuild $solutionFileName /t:$buildTrgClean /p:VisualStudioVersion=15.0 /p:Configuration=$configurationName /m
  67. }
  68. Write-Host("***** END *** CLEANS SOLUTION/PROJECT : {0} *****" -f $solutionFileName) -ForegroundColor DarkYellow
  69. #/p:SolutionDir=$location /m
  70. }
  71. # Returns list of project from solution file. Returns objects with properties: Name, File, Guid, Directory
  72. Function GetProjectsFromSolution
  73. {
  74. param(
  75. # Solution file name with full path
  76. [string] $solutionFileName
  77. )
  78. $fileExists = Test-Path($solutionFileName)
  79. if ($fileExists -eq $false){
  80. Write-Error("Solution file '{0}' doesn't exists." -f $solutionFileName)
  81. Break
  82. }
  83. return Get-Content $solutionFileName |
  84. Select-String 'Project\(' |
  85. ForEach-Object {
  86. $projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') };
  87. New-Object PSObject -Property @{
  88. Name = $projectParts[1];
  89. File = $projectParts[2];
  90. Guid = $projectParts[3];
  91. Directory = Split-Path -Path "$projectDir\$($projectParts[2])" -Parent
  92. }
  93. }
  94. }
  95. Write-Host "QDS library was loaded." -ForegroundColor DarkGray