Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate McMaster <natemcmaster@users.noreply.github.com>2019-02-20 22:20:34 +0300
committerGitHub <noreply@github.com>2019-02-20 22:20:34 +0300
commit6fea3a6e95a36c3fff49057a8cf67632272ac4d0 (patch)
treedee441a24a422295410459c0e4d76cb2c7caf215 /activate.ps1
parent9a2db43848e9527d969b41cbee9c7739f8dbb0c5 (diff)
Show error message when activate.sh/ps1 is invoked directly instead of sourced (#7731)
Helps users avoid a common mistake which is otherwise not obvious.
Diffstat (limited to 'activate.ps1')
-rw-r--r--activate.ps19
1 files changed, 8 insertions, 1 deletions
diff --git a/activate.ps1 b/activate.ps1
index 78e8557fc8..194ac8d349 100644
--- a/activate.ps1
+++ b/activate.ps1
@@ -1,9 +1,16 @@
#
# This file must be used by invoking ". .\activate.ps1" from the command line.
-# You cannot run it directly.
+# You cannot run it directly. See https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_scripts#script-scope-and-dot-sourcing
+#
# To exit from the environment this creates, execute the 'deactivate' function.
#
+if ($MyInvocation.CommandOrigin -eq 'runspace') {
+ Write-Host -f Red "This script cannot be invoked directly."
+ Write-Host -f Red "To function correctly, this script file must be 'dot sourced' by calling `". $PSCommandPath`" (notice the dot at the beginning)."
+ exit 1
+}
+
function deactivate ([switch]$init) {
# reset old environment variables