Terminal.Gui.PowerShell.Analyzers.psm1 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <#
  2. .SYNOPSIS
  3. Builds all analyzer projects in Debug and Release configurations.
  4. .DESCRIPTION
  5. Uses dotnet build to build all analyzer projects, with optional behavior changes via switch parameters.
  6. .PARAMETER AutoClose
  7. Automatically close running Visual Studio processes which have the Terminal.sln solution loaded, before taking any other actions.
  8. .PARAMETER AutoLaunch
  9. Automatically start a new Visual Studio process and load the solution after completion.
  10. .PARAMETER Force
  11. Carry out operations unconditionally and do not prompt for confirmation.
  12. .PARAMETER NoClean
  13. Do not delete the bin and obj folders before building the analyzers. Usually best not to use this, but can speed up the builds slightly.
  14. .PARAMETER Quiet
  15. Write less text output to the terminal.
  16. .INPUTS
  17. None
  18. .OUTPUTS
  19. None
  20. #>
  21. Function Build-Analyzers {
  22. [CmdletBinding()]
  23. param(
  24. [Parameter(Mandatory=$false, HelpMessage="Automatically close running Visual Studio processes which have the Terminal.sln solution loaded, before taking any other actions.")]
  25. [switch]$AutoClose,
  26. [Parameter(Mandatory=$false, HelpMessage="Automatically start a new Visual Studio process and load the solution after completion.")]
  27. [switch]$AutoLaunch,
  28. [Parameter(Mandatory=$false, HelpMessage="Carry out operations unconditionally and do not prompt for confirmation.")]
  29. [switch]$Force,
  30. [Parameter(Mandatory=$false, HelpMessage="Do not delete the bin and obj folders before building the analyzers.")]
  31. [switch]$NoClean,
  32. [Parameter(Mandatory=$false, HelpMessage="Write less text output to the terminal.")]
  33. [switch]$Quiet
  34. )
  35. if($AutoClose) {
  36. if(!$Quiet) {
  37. Write-Host Closing Visual Studio processes
  38. }
  39. Close-Solution
  40. }
  41. if($Force){
  42. $response = 'Y'
  43. }
  44. elseif(!$Force && $NoClean){
  45. $response = ($r = Read-Host "Pre-build Terminal.Gui.InternalAnalyzers without removing old build artifacts? [Y/n]") ? $r : 'Y'
  46. }
  47. else{
  48. $response = ($r = Read-Host "Delete bin and obj folders for Terminal.Gui and Terminal.Gui.InternalAnalyzers and pre-build Terminal.Gui.InternalAnalyzers? [Y/n]") ? $r : 'Y'
  49. }
  50. if (($response -ne 'Y')) {
  51. Write-Host Took no action
  52. return
  53. }
  54. New-Variable -Name solutionRoot -Visibility Public -Value (Resolve-Path ..)
  55. Push-Location $solutionRoot
  56. New-Variable -Name solutionFile -Visibility Public -Value (Resolve-Path ./Terminal.sln)
  57. $mainProjectRoot = Resolve-Path ./Terminal.Gui
  58. $mainProjectFile = Join-Path $mainProjectRoot Terminal.Gui.csproj
  59. $analyzersRoot = Resolve-Path ./Analyzers
  60. $internalAnalyzersProjectRoot = Join-Path $analyzersRoot Terminal.Gui.Analyzers.Internal
  61. $internalAnalyzersProjectFile = Join-Path $internalAnalyzersProjectRoot Terminal.Gui.Analyzers.Internal.csproj
  62. if(!$NoClean) {
  63. if(!$Quiet) {
  64. Write-Host Deleting bin and obj folders for Terminal.Gui
  65. }
  66. if(Test-Path $mainProjectRoot/bin) {
  67. Remove-Item -Recurse -Force $mainProjectRoot/bin
  68. Remove-Item -Recurse -Force $mainProjectRoot/obj
  69. }
  70. if(!$Quiet) {
  71. Write-Host Deleting bin and obj folders for Terminal.Gui.InternalAnalyzers
  72. }
  73. if(Test-Path $internalAnalyzersProjectRoot/bin) {
  74. Remove-Item -Recurse -Force $internalAnalyzersProjectRoot/bin
  75. Remove-Item -Recurse -Force $internalAnalyzersProjectRoot/obj
  76. }
  77. }
  78. if(!$Quiet) {
  79. Write-Host Building analyzers in Debug configuration
  80. }
  81. dotnet build $internalAnalyzersProjectFile --no-incremental --nologo --force --configuration Debug
  82. if(!$Quiet) {
  83. Write-Host Building analyzers in Release configuration
  84. }
  85. dotnet build $internalAnalyzersProjectFile --no-incremental --nologo --force --configuration Release
  86. if(!$AutoLaunch) {
  87. Write-Host -ForegroundColor Green Finished. Restart Visual Studio for changes to take effect.
  88. } else {
  89. if(!$Quiet) {
  90. Write-Host -ForegroundColor Green Finished. Re-loading Terminal.sln.
  91. }
  92. Open-Solution
  93. }
  94. return
  95. }