代码之家  ›  专栏  ›  技术社区  ›  craig

在启动Visual Studio for Mac时加载PowerShell模块以进行调试

  •  0
  • craig  · 技术社区  · 6 年前

    我正在使用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]] [-Command{-|[-args] | [] } ] [-ConfigurationName][-EncodedCommand] [-ExecutionPolicy][-InputFormat{Text | XML}] [-Interactive][-NoExit][-NoLogo][-NonInteractive][-NoProfile] [-OutputFormat{Text | XML}][-Version][-WindowStyle] [-工作目录]

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

    PowerShell联机帮助 https://aka.ms/pscore6-docs

    所有参数都不区分大小写。应用程序已由终止 未知信号:当前平台不支持此值。 参数名称:值实际值为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"

    我换了 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 \> 似乎不接受输入。

    **/编辑0**

    **编辑1**

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

    enter image description here

    它按预期加载了模块:

    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>
    

    **/编辑1**

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   SushiHangover    6 年前

    您需要将项目目标目录指定为“ 在目录中运行

    enter image description here

    推荐文章