Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/powershell-win-core/Microsoft.PowerShell_profile.ps1
Original file line number Diff line number Diff line change
@@ -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\"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only gets the default, if the Windows PSModulePath is modified by installing Azure cmdlets or SQL, then they won't be available. We would need something like this:

$env:PSModulePath += (";" + (& ${env:windir}\system32\windowspowershell\v1.0\powershell.exe '$env:PSModulePath'))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling out to Windows PowerShell can incur a 150-250ms startup penalty. Since this change isn't intended to be the final solution and just helps to get customer feedback, I think we are ok with it not being 100% accurate. Advanced customers can update their PSModulePath as needed.

}
6 changes: 3 additions & 3 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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'
}
}
15 changes: 15 additions & 0 deletions test/powershell/engine/Module/ModulePath.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}