activate.ps1 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #
  2. # This file must be used by invoking ". .\activate.ps1" from the command line.
  3. # You cannot run it directly. See https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_scripts#script-scope-and-dot-sourcing
  4. #
  5. # To exit from the environment this creates, execute the 'deactivate' function.
  6. #
  7. if ($MyInvocation.CommandOrigin -eq 'runspace') {
  8. Write-Host -f Red "This script cannot be invoked directly."
  9. Write-Host -f Red "To function correctly, this script file must be 'dot sourced' by calling `". $PSCommandPath`" (notice the dot at the beginning)."
  10. exit 1
  11. }
  12. function deactivate ([switch]$init) {
  13. # reset old environment variables
  14. if (Test-Path variable:_OLD_PATH) {
  15. $env:PATH = $_OLD_PATH
  16. Remove-Item variable:_OLD_PATH
  17. }
  18. if (test-path function:_old_prompt) {
  19. Set-Item Function:prompt -Value $function:_old_prompt -ea ignore
  20. remove-item function:_old_prompt
  21. }
  22. Remove-Item env:DOTNET_ROOT -ea ignore
  23. Remove-Item 'env:DOTNET_ROOT(x86)' -ea Ignore
  24. if (-not $init) {
  25. # Remove the deactivate function
  26. Remove-Item function:deactivate
  27. }
  28. }
  29. # Cleanup the environment
  30. deactivate -init
  31. $_OLD_PATH = $env:PATH
  32. # Tell dotnet where to find itself
  33. $env:DOTNET_ROOT = "$PSScriptRoot\.dotnet"
  34. ${env:DOTNET_ROOT(x86)} = "$PSScriptRoot\.dotnet\x86"
  35. # Put dotnet first on PATH
  36. $env:PATH = "${env:DOTNET_ROOT};${env:PATH}"
  37. # Set the shell prompt
  38. if (-not $env:DISABLE_CUSTOM_PROMPT) {
  39. $function:_old_prompt = $function:prompt
  40. function dotnet_prompt {
  41. # Add a prefix to the current prompt, but don't discard it.
  42. write-host "($( split-path $PSScriptRoot -leaf )) " -nonewline
  43. & $function:_old_prompt
  44. }
  45. Set-Item Function:prompt -Value $function:dotnet_prompt -ea ignore
  46. }
  47. Write-Host -f Magenta "Enabled the .NET Core environment. Execute 'deactivate' to exit."
  48. if (-not (Test-Path "${env:DOTNET_ROOT}\dotnet.exe")) {
  49. Write-Host -f Yellow ".NET Core has not been installed yet. Run $PSScriptRoot\restore.cmd to install it."
  50. }
  51. else {
  52. Write-Host "dotnet = ${env:DOTNET_ROOT}\dotnet.exe"
  53. }