简体   繁体   English

从Visual Studio /代码运行时,PowerShell不会加载所有PSModulePaths

[英]PowerShell does not load all PSModulePaths when running from Visual Studio / Code

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. 我对这里问题的回答中可以看出,由于某种原因,当我从Visual Studio中的代码运行PowerShell时,无论是通过调用powershell.Invoke还是通过启动新的PowerShell进程,它都不包括所有的PSModulePaths 。手动启动Windows PowerShell命令提示符时包含在内。

If I do (Get-Item Env:\\PSModulePath).Value -Split ';' 如果我这样做(Get-Item Env:\\PSModulePath).Value -Split ';' in a regular Windows PowerShell command prompt I get the following 7 paths: 在常规Windows PowerShell命令提示符下,我得到以下7条路径:

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

However, if I run it from code I get the following 3 paths: 但是,如果我通过代码运行它,则会得到以下3条路径:

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

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 (eg Get-Date , Test-Path , etc.). 因为当我从代码运行时,它不包含C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\ ,所以大量的默认内置cmdlet不可用(例如, Get-DateTest-Path等)。 )。

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. 我卸载了StudioShell (Visual Studio PowerShell扩展),现在一切正常。 It looks like there is a bug in that extension. 似乎该扩展程序中存在错误。

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. 在我的问题中,您可以看到它是我从Visual Studio中运行时列出的最后一个PSModulePath,并且它具有相对路径,而其余路径具有绝对路径。

I'll open a new bug for StudioShell to get this fixed up. 我将为StudioShell打开一个新错误以修复此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Powershell 中运行时与在 Visual Studio 中运行时的 HttpClient 并发行为不同 - HttpClient concurrent behavior different when running in Powershell than in Visual Studio 从 Visual Studio 2019 运行控制台应用程序时如何加载 usersecrets 文件 - How do I get the usersecrets file to load when running a console app from Visual Studio 2019 在 Visual Studio 上通过 IIS Express 运行时可以加载图像,但通过 IIS 运行时无法加载 - Image can load when running by IIS Express on Visual studio, but can't load when running by IIS Visual Studio在运行Web Project时删除源代码 - Visual Studio deleting source code when running Web Project 如何判断代码是否从Visual Studio / Cassini本地运行 - How to tell if code is running locally from Visual Studio/Cassini 导入错误:在通过 CFFI 从 Visual Studio C# 运行 Python 时,导入 _fblas 时 DLL 加载失败 - ImportError: DLL load failed while importing _fblas, when running Python from Visual Studio C# via CFFI 为什么此代码仅在从Visual Studio内部运行时才起作用? - Why does this code only work when run from inside Visual Studio but not otherwise? 在Visual Studio外部运行时从WPF窗口中删除图标 - Removing the icon from a WPF window when running outside of Visual Studio 从Visual Studio运行应用程序时,其性能会下降 - Application's performance deteriorates when running it from Visual Studio 从Visual Studio运行项目时找不到文件异常 - File not found exception when running project from Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM