002_library.ps1 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: 29.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. # Publish solution file, may calls CleanSolution
  72. Function PublishSolution
  73. {
  74. param(
  75. # Solution file name with full path
  76. [string] $solutionFileName,
  77. # Build configuration Debug / Release
  78. [string] $configurationName = $buildCfgDebug,
  79. # Defines alternative output directory. If not defined, use default output locations depends on configuration
  80. [string] $alternativeOutputDirectory,
  81. # Defines if Clean will be called before build
  82. [bool] $cleanBeforeBuild = $false,
  83. # Defines if only show calling commands instead of executes them (just for debugging)
  84. [bool] $simulate = $false
  85. )
  86. $fileExists = Test-Path($solutionFileName)
  87. if ($fileExists -eq $false){
  88. Write-Error("Solution file '{0}' doesn't exists." -f $solutionFileName)
  89. Break
  90. }
  91. if (!$alternativeOutputDirectory){
  92. $alternativeOutputDirectory = ""
  93. }
  94. else{
  95. $alternativeOutputDirectory = " /p:PublishDestination='{0}'" -f $alternativeOutputDirectory
  96. }
  97. Write-Host("**** BEGIN *** BUILDS SOLUTION/PROJECT : {0} ****" -f $solutionFileName) -ForegroundColor Yellow
  98. if ($cleanBeforeBuild -eq $true){
  99. CleanSolution $solutionFileName $configurationName $simulate
  100. }
  101. if ($simulate -eq $true){
  102. Write-Host "msbuild $solutionFileName /t:$buildTrgPublish /p:VisualStudioVersion=15.0 /p:Configuration=$configurationName /m /clp:Summary /clp:ShowTimestamp $alternativeOutputDirectory" -ForegroundColor Cyan
  103. } else{
  104. msbuild $solutionFileName /t:$buildTrgPublish /p:VisualStudioVersion=15.0 /p:Configuration=$configurationName /m /clp:Summary /clp:ShowTimestamp $alternativeOutputDirectory
  105. }
  106. Write-Host("**** END *** BUILDS SOLUTION/PROJECT : {0} ****" -f $solutionFileName) -ForegroundColor Yellow
  107. }
  108. # Returns list of project from solution file. Returns objects with properties: Name, File, Guid, Directory
  109. Function GetProjectsFromSolution
  110. {
  111. param(
  112. # Solution file name with full path
  113. [string] $solutionFileName
  114. )
  115. $fileExists = Test-Path($solutionFileName)
  116. if ($fileExists -eq $false){
  117. Write-Error("Solution file '{0}' doesn't exists." -f $solutionFileName)
  118. Break
  119. }
  120. return Get-Content $solutionFileName |
  121. Select-String 'Project\(' |
  122. ForEach-Object {
  123. $projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') };
  124. New-Object PSObject -Property @{
  125. Name = $projectParts[1];
  126. File = $projectParts[2];
  127. Guid = $projectParts[3];
  128. Directory = Split-Path -Path "$projectDir\$($projectParts[2])" -Parent
  129. }
  130. }
  131. }
  132. Write-Host "QDS library was loaded." -ForegroundColor DarkGray