activate.ps1 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # This file must be used by invoking ". .\activate.ps1" from the command line.
  3. # You cannot run it directly. See https://docs.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_MULTILEVEL_LOOKUP -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\x64"
  34. # Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things
  35. $env:DOTNET_MULTILEVEL_LOOKUP = 0
  36. # Put dotnet first on PATH
  37. $env:PATH = "${env:DOTNET_ROOT};${env:PATH}"
  38. # Set the shell prompt
  39. if (-not $env:DISABLE_CUSTOM_PROMPT) {
  40. $function:_old_prompt = $function:prompt
  41. function dotnet_prompt {
  42. # Add a prefix to the current prompt, but don't discard it.
  43. write-host "($( split-path $PSScriptRoot -leaf )) " -nonewline
  44. & $function:_old_prompt
  45. }
  46. Set-Item Function:prompt -Value $function:dotnet_prompt -ea ignore
  47. }
  48. Write-Host -f Magenta "Enabled the .NET Core environment. Execute 'deactivate' to exit."
  49. if (-not (Test-Path "${env:DOTNET_ROOT}\dotnet.exe")) {
  50. Write-Host -f Yellow ".NET Core has not been installed yet. Run $PSScriptRoot\restore.cmd to install it."
  51. }
  52. else {
  53. Write-Host "dotnet = ${env:DOTNET_ROOT}\dotnet.exe"
  54. }