【问题标题】:Load a PowerShell module for debugging when starting Visual Studio for Mac启动 Visual Studio for Mac 时加载 PowerShell 模块以进行调试
【发布时间】:2019-01-11 01:25:33
【问题描述】:

我正在使用 Visual Studio for Mac(7.7.2;内部版本 21)使用 C# 创建 PowerShell 提供程序。

我想让 IDE 加载 PowerShell 进行调试。

项目的运行配置:

  • 启动外部项目:/usr/local/bin/pwsh
  • 参数:-NoProfile -NoExit -File "./InstallProvider.ps1"

InstallProvider.ps1:

Import-Module "./PsMyModule.psd1" -Force -Verbose

PsMyModule.psd1:

@{
  # Script module or binary module file associated with this manifest.
  RootModule = 'PsMyModule.dll'
}

两个文件 (ps1,psd1) 都标记为 Copy to output

当我在调试模式下运行项目时,我得到这个错误:

参数“./InstallProvider.ps1”未被识别为 一个脚本文件。检查名称的拼写,或者路径是否 包含,请验证路径是否正确,然后重试。

用法:pwsh[.exe] [[-File] [args]] [-命令{ - | [-args] | []}] [-ConfigurationName] [-EncodedCommand] [-ExecutionPolicy ] [-InputFormat {Text | XML}] [-Interactive] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile] [-输出格式 {文本 | XML}] [-版本] [-WindowStyle ] [-工作目录]

   pwsh[.exe] -h | -Help | -? | /?

PowerShell 在线帮助https://aka.ms/pscore6-docs

所有参数都不区分大小写。申请被终止 未知信号:当前平台不支持此值。 参数名称:value 实际值为64。

但是,当我从终端运行 pwsh 时,它按预期加载了模块:

~/.../bin/Debug/netstandard2.0$ pwsh -NoExit -File "./InstallProvider.ps1"
PowerShell 6.1.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

VERBOSE: Loading module from path '/Users/[user]/Projects/Visual Studio 2017/PsMyModule/bin/Debug/netstandard2.0/PsMyModule.psd1'.
VERBOSE: Loading module from path '/Users/[user]/Projects/Visual Studio 2017/PsMyModule/bin/Debug/netstandard2.0/PsMyModule.dll'.

这些变体都不起作用:

  • -File ".\InstallProvider.ps1"
  • -File InstallProvider.ps1
  • -File "./InstallProvider.ps1"

** 编辑 0 **

我把File参数改成了"/Users/[user]/Projects/Visual Studio 2017/PsMyModule/bin/Debug/netstandard2.0/InstallProvider.ps1"

PowerShell 6.1.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

Import-Module : The specified module './PsMyModule.psd1' was not loaded because no valid module file was found in any module directory.
At /Users/[user]/Projects/Visual Studio 2017/PsMyModule/bin/Debug/netstandard2.0/InstallProvider.ps1:1 char:1
+ Import-Module "./PsMyModule.psd1" -Force -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (./PsMyModule.psd1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

PS /> 

似乎没有正确解释相对路径。此外,提示PS \> 似乎不接受输入。

** /edit 0 **

** 编辑 1 **

我在 Visual Studio 2017 for Windows 中创建了一个类似的项目。调试设置:

按预期加载了模块:

VERBOSE: Loading module from path 'C:\Users\XXX\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\netstandard2.0\FooModule.psd1'.
VERBOSE: Loading module from path 'C:\Users\XXX\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\netstandard2.0\FooModule.dll'.
PS C:\Users\XXX\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\netstandard2.0>

** /edit 1 **

我错过了什么? OS X 版本有什么不同?

【问题讨论】:

  • 你试过ps1文件的完整路径吗?

标签: powershell visual-studio-2017 visual-studio-mac powershell-v6.0


【解决方案1】:

您需要将项目目标目录分配为“在目录中运行”,因为您没有启动项目,工作环境将基于VS4M的环境,并且shell不在项目调试/发布目录输出:

【讨论】:

  • 这可行,但提示 (PS \>) 似乎不接受输入。
  • 我已签入 run on external consolepause console output 运行 |配置 |默认。这是否应该打开一个新的终端窗口,然后启动pwsh
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-19
  • 2023-03-07
相关资源
最近更新 更多