activate.ps1 2.3 KB

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