Add Windows PowerShell PSModulePath by default on Windows (#4132)
This change is only for Windows and appends the Windows PowerShell PSModulePath on startup via a default profile. Depending on the data/feedback we get, we can decide what to do (opt-in vs opt-out) as we get closer to a release candidate.
This commit is contained in:
parent
51c7861da6
commit
7bce1653f3
12
build.psm1
12
build.psm1
@ -191,12 +191,12 @@ function Start-PSBuild {
|
||||
# verify we have all tools in place to do the build
|
||||
$precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH. Run Start-PSBootstrap. Also see: https://dotnet.github.io/getting-started/"
|
||||
|
||||
$dotnetCLIIntalledVersion = (dotnet --version)
|
||||
If ( $dotnetCLIIntalledVersion -ne $dotnetCLIRequiredVersion ) {
|
||||
$dotnetCLIInstalledVersion = (dotnet --version)
|
||||
If ( $dotnetCLIInstalledVersion -ne $dotnetCLIRequiredVersion ) {
|
||||
Write-Warning @"
|
||||
The currently installed .NET Command Line Tools is not the required version.
|
||||
|
||||
Installed version: $dotnetCLIIntalledVersion
|
||||
Installed version: $dotnetCLIInstalledVersion
|
||||
Required version: $dotnetCLIRequiredVersion
|
||||
|
||||
Fix steps:
|
||||
@ -472,6 +472,12 @@ cmd.exe /C cd /d "$location" "&" "$($vcVarsPath)\vcvarsall.bat" "$NativeHostArch
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# copy PowerShell host profile if Windows
|
||||
if ($IsWindows)
|
||||
{
|
||||
Copy-Item -Path "$PSScriptRoot/src/powershell-win-core/Microsoft.PowerShell_profile.ps1" -Destination $publishPath -Force
|
||||
}
|
||||
|
||||
# download modules from powershell gallery.
|
||||
# - PowerShellGet, PackageManagement, Microsoft.PowerShell.Archive
|
||||
if($PSModuleRestore)
|
||||
|
10
src/powershell-win-core/Microsoft.PowerShell_profile.ps1
Normal file
10
src/powershell-win-core/Microsoft.PowerShell_profile.ps1
Normal file
@ -0,0 +1,10 @@
|
||||
# Default profile for all users for PowerShell host
|
||||
|
||||
if ($IsWindows)
|
||||
{
|
||||
# Add Windows PowerShell PSModulePath to make it easier to discover potentially compatible PowerShell modules
|
||||
# If a Windows PowerShell module works or not, please provide feedback at https://github.com/PowerShell/PowerShell/issues/4062
|
||||
|
||||
Write-Warning "Appended Windows PowerShell PSModulePath"
|
||||
$env:psmodulepath += ";${env:userprofile}\Documents\WindowsPowerShell\Modules;${env:programfiles}\WindowsPowerShell\Modules;${env:windir}\system32\WindowsPowerShell\v1.0\Modules\"
|
||||
}
|
@ -179,7 +179,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
||||
|
||||
It "-File should be default parameter" {
|
||||
Set-Content -Path $testdrive/test -Value "'hello'"
|
||||
$observed = & $powershell $testdrive/test
|
||||
$observed = & $powershell -NoProfile $testdrive/test
|
||||
$observed | Should Be "hello"
|
||||
}
|
||||
|
||||
@ -189,13 +189,13 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
||||
) {
|
||||
param($Filename)
|
||||
Set-Content -Path $testdrive/$Filename -Value "'hello'"
|
||||
$observed = & $powershell -File $testdrive/$Filename
|
||||
$observed = & $powershell -NoProfile -File $testdrive/$Filename
|
||||
$observed | Should Be "hello"
|
||||
}
|
||||
|
||||
It "-File should pass additional arguments to script" {
|
||||
Set-Content -Path $testdrive/script.ps1 -Value 'foreach($arg in $args){$arg}'
|
||||
$observed = & $powershell $testdrive/script.ps1 foo bar
|
||||
$observed = & $powershell -NoProfile $testdrive/script.ps1 foo bar
|
||||
$observed.Count | Should Be 2
|
||||
$observed[0] | Should Be "foo"
|
||||
$observed[1] | Should Be "bar"
|
||||
|
@ -14,16 +14,16 @@ Describe "Out-Default Tests" -tag CI {
|
||||
`$null = Stop-Transcript
|
||||
"@
|
||||
|
||||
& $powershell -c $script | Should BeExactly 'bye'
|
||||
& $powershell -noprofile -command $script | Should BeExactly 'bye'
|
||||
"TestDrive:\transcript.txt" | Should Contain 'hello'
|
||||
}
|
||||
|
||||
It "Out-Default reverts transcription state when used more than once in a pipeline" {
|
||||
& $powershell -c "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should BeExactly "Hello"
|
||||
& $powershell -noprofile -command "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should BeExactly "Hello"
|
||||
}
|
||||
|
||||
It "Out-Default reverts transcription state when exception occurs in pipeline" {
|
||||
& $powershell -c "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should BeExactly "Hello"
|
||||
& $powershell -noprofile -command "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should BeExactly "Hello"
|
||||
}
|
||||
|
||||
It "Out-Default reverts transcription state even if Dispose() isn't called" {
|
||||
@ -35,6 +35,6 @@ Describe "Out-Default Tests" -tag CI {
|
||||
[GC]::WaitForPendingFinalizers();
|
||||
'hello'
|
||||
"@
|
||||
& $powershell -c $script | Should BeExactly 'hello'
|
||||
& $powershell -noprofile -command $script | Should BeExactly 'hello'
|
||||
}
|
||||
}
|
||||
|
@ -93,4 +93,19 @@ Describe "SxS Module Path Basic Tests" -tags "CI" {
|
||||
$paths -contains $fakePSHomeModuleDir | Should Be $true
|
||||
$paths -contains $customeModules | Should Be $true
|
||||
}
|
||||
|
||||
It "Default PowerShell profile appends Windows PowerShell PSModulePath only on Windows" {
|
||||
|
||||
$psmodulepath = & $powershell -nologo -c '$env:PSModulePath'
|
||||
|
||||
if ($IsWindows)
|
||||
{
|
||||
$psmodulepath[0] | Should Match "Warning" # for Windows, there is a warning that path being appended
|
||||
$psmodulepath[1] | Should Match "WindowsPowerShell"
|
||||
}
|
||||
else
|
||||
{
|
||||
$psmodulepath[0] | Should Not Match "WindowsPowerShell"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user