Terminal.Gui.PowerShell.psm1 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Function Build-Analyzers {
  2. [CmdletBinding()]
  3. param(
  4. [Parameter(Mandatory=$false, HelpMessage="Automatically close running Visual Studio processes which have the Terminal.sln solution loaded, before taking any other actions.")]
  5. [switch]$AutoClose,
  6. [Parameter(Mandatory=$false, HelpMessage="Automatically start a new Visual Studio process and load the solution after completion.")]
  7. [switch]$AutoLaunch,
  8. [Parameter(Mandatory=$false, HelpMessage="Carry out operations unconditionally and do not prompt for confirmation.")]
  9. [switch]$Force,
  10. [Parameter(Mandatory=$false, HelpMessage="Do not delete the bin and obj folders before building the analyzers.")]
  11. [switch]$NoClean,
  12. [Parameter(Mandatory=$false, HelpMessage="Write less text output to the terminal.")]
  13. [switch]$Quiet
  14. )
  15. if($AutoClose) {
  16. if(!$Quiet) {
  17. Write-Host Closing Visual Studio processes
  18. }
  19. Close-Solution
  20. }
  21. if($Force){
  22. $response = 'Y'
  23. }
  24. elseif(!$Force && $NoClean){
  25. $response = ($r = Read-Host "Pre-build Terminal.Gui.InternalAnalyzers without removing old build artifacts? [Y/n]") ? $r : 'Y'
  26. }
  27. else{
  28. $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'
  29. }
  30. if (($response -ne 'Y')) {
  31. Write-Host Took no action
  32. return
  33. }
  34. New-Variable -Name solutionRoot -Visibility Public -Value (Resolve-Path ..)
  35. Push-Location $solutionRoot
  36. New-Variable -Name solutionFile -Visibility Public -Value (Resolve-Path ./Terminal.sln)
  37. $mainProjectRoot = Resolve-Path ./Terminal.Gui
  38. $mainProjectFile = Join-Path $mainProjectRoot Terminal.Gui.csproj
  39. $analyzersRoot = Resolve-Path ./Analyzers
  40. $internalAnalyzersProjectRoot = Join-Path $analyzersRoot Terminal.Gui.Analyzers.Internal
  41. $internalAnalyzersProjectFile = Join-Path $internalAnalyzersProjectRoot Terminal.Gui.Analyzers.Internal.csproj
  42. if(!$NoClean) {
  43. if(!$Quiet) {
  44. Write-Host Deleting bin and obj folders for Terminal.Gui
  45. }
  46. if(Test-Path $mainProjectRoot/bin) {
  47. Remove-Item -Recurse -Force $mainProjectRoot/bin
  48. Remove-Item -Recurse -Force $mainProjectRoot/obj
  49. }
  50. if(!$Quiet) {
  51. Write-Host Deleting bin and obj folders for Terminal.Gui.InternalAnalyzers
  52. }
  53. if(Test-Path $internalAnalyzersProjectRoot/bin) {
  54. Remove-Item -Recurse -Force $internalAnalyzersProjectRoot/bin
  55. Remove-Item -Recurse -Force $internalAnalyzersProjectRoot/obj
  56. }
  57. }
  58. if(!$Quiet) {
  59. Write-Host Building analyzers in Debug configuration
  60. }
  61. dotnet build $internalAnalyzersProjectFile --no-incremental --nologo --force --configuration Debug
  62. if(!$Quiet) {
  63. Write-Host Building analyzers in Release configuration
  64. }
  65. dotnet build $internalAnalyzersProjectFile --no-incremental --nologo --force --configuration Release
  66. if(!$AutoLaunch) {
  67. Write-Host -ForegroundColor Green Finished. Restart Visual Studio for changes to take effect.
  68. } else {
  69. if(!$Quiet) {
  70. Write-Host -ForegroundColor Green Finished. Re-loading Terminal.sln.
  71. }
  72. Open-Solution
  73. }
  74. return
  75. }
  76. Function Open-Solution {
  77. Invoke-Item $solutionFile
  78. return
  79. }
  80. Function Close-Solution {
  81. $vsProcesses = Get-Process -Name devenv | Where-Object { ($_.CommandLine -Match ".*Terminal\.sln.*" -or $_.MainWindowTitle -Match "Terminal.*") }
  82. Stop-Process -InputObject $vsProcesses
  83. Remove-Variable vsProcesses
  84. }
  85. Export-ModuleMember -Function Build-Analyzers
  86. Export-ModuleMember -Function Open-Solution
  87. Export-ModuleMember -Function Close-Solution