从 Visual Studio/Code 运行时,PowerShell 不会加载所有 PSModulePaths [英] PowerShell does not load all PSModulePaths when running from Visual Studio / Code

查看:90
本文介绍了从 Visual Studio/Code 运行时,PowerShell 不会加载所有 PSModulePaths的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您从 我在这里对我的问题的回答中所看到的,出于某种原因,当我从 Visual Studio 中的代码运行 PowerShell 时,通过调用 powershell.Invoke,或通过启动新的 PowerShell 进程,它不包括所有 PSModulePaths,在我手动启动 Windows PowerShell 命令提示符时包含.

As you can see from my answer on my question here, for some reason when I run PowerShell from code in Visual Studio, either by calling powershell.Invoke, or by starting a new PowerShell process, it does not include all of the PSModulePaths that are included when I manually startup a Windows PowerShell command prompt.

如果我在常规 Windows PowerShell 命令提示符下执行 (Get-Item Env:\PSModulePath).Value -Split ';',我会得到以下 7 个路径:

If I do (Get-Item Env:\PSModulePath).Value -Split ';' in a regular Windows PowerShell command prompt I get the following 7 paths:

C:\Users\Dan Schroeder\Documents\WindowsPowerShell\Modules\
C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
C:\Program Files\Microsoft Security Client\MpProvider\
C:\Program Files (x86)\\Code Owls LLC

但是,如果我从代码运行它,我会得到以下 3 条路径:

However, if I run it from code I get the following 3 paths:

C:\Users\Dan Schroeder\Documents\WindowsPowerShell\Modules\
C:\Users\Dan Schroeder\Documents\WindowsPowershell\Modules
C:\Program Files (x86)\Code Owls LLC\StudioShell\bin\\..\\..

为什么这些如此不同?由于当我从代码运行时它不包括 C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\,大量默认的内置 cmdlet 不可用(例如 Get-DateTest-Path 等).

Why are these so different? Since when I run from code it doesn't include C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\, tons of the default built-in cmdlets are not available (e.g. Get-Date, Test-Path, etc.).

推荐答案

我找到了问题的原因,它隐藏在我的问题中.我卸载了 StudioShell(Visual Studio PowerShell 扩展),现在一切正常.该扩展程序中似乎存在错误.

I found the cause of the problem, which was hidden in my question. I uninstalled StudioShell (a Visual Studio PowerShell extension) and everything works correctly now. It looks like there is a bug in that extension.

在我的问题中,您可以看到它是我从 Visual Studio 运行时列出的最后一个 PSModulePath,并且它具有相对路径,其余路径具有绝对路径.

In my question you can see that it is the last PSModulePath listed when I ran from Visual Studio, and that it has a relative path, where the rest of them have an absolute path.

我将为 StudioShell 打开一个新错误以修复此问题.

I'll open a new bug for StudioShell to get this fixed up.

这篇关于从 Visual Studio/Code 运行时,PowerShell 不会加载所有 PSModulePaths的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆