activate.ps1 2.2 KB

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