在 Visual Studio PowerShell window 中包含自定义 cmdlet

Include custom cmdlets in Visual Studio PowerShell window

我公司正在使用 Visual Studio 2015,它有非常实用的 PowerShell Interactive Window 和 NuGet Paket Manager Console,它基本上是一个 PowerShell 主机。

我们想在其中一个 windows 中使用我们自己的一些 cmdlet。有什么方法可以配置为加载它们 'automatically',类似于 PowerShell 中的自动加载用户配置文件?如果可能,最好基于当前打开的解决方案。

请考虑:使用常规 PowerShell 配置文件将不起作用,因为它未加载到这些 windows 中。此外,即使它确实有效,这也只是基于每个用户的解决方案。

(注意:这些 cmdlet 是脚本 cmdlet,但我 think/hope 这不会有太大区别。)

启动您的 powershell 交互式/Nuget 包管理器 window 并键入 $profile。您会看到您的配置文件的定义位置。然后,您可以将自己的 cmdlet 添加到该配置文件中。有关详细信息,请参阅 this article