Debug-Job :The job cannot be debugged because the host debugger mode is set to None or Default

杀马特。学长 韩版系。学妹 提交于 2019-12-08 05:57:23

问题


I created a sample powershell project with a Script.ps1 file and a Modules\Script1\Script1.psm1 file.

the module file..

# Script1.psm1
function Get-Greeting{
    Start-Sleep -Seconds 10
    Write-Host "hello from foo";
}

and the script file..

# Script1.ps1
if(-not(Get-Module -Name "Script1")){
    Import-Module .\Modules\Script1
}
if(Get-Module -Name "Script1"){
    Remove-Module Script1;
    Import-Module .\Modules\Script1;
}

Get-Greeting # output: hello from foo
$ajob = Start-Job -ScriptBlock {
    Get-Greeting
} -InitializationScript {

    if(-not(Get-Module -Name "Script1")){
        Import-Module 'C:\Users\suyashs\Documents\Visual Studio 2015\Projects\Playground\PowerShellProject2\PowerShellProject2\Modules\Script1'
    }
    if(Get-Module -Name "Script1"){
        Remove-Module Script1;
        Import-Module 'C:\Users\suyashs\Documents\Visual Studio 2015\Projects\Playground\PowerShellProject2\PowerShellProject2\Modules\Script1'
    }
} 

Debug-Job -Job $ajob

Error appears at last line Debug-Job -Job $ajob

[ERROR] Debug-Job : The job cannot be debugged because the host debugger mode is set to None or Default. The host debugger mode must be [ERROR] LocalScript and/or RemoteSript

What i want is that the breakpoint inside my Get-Greeting method gets hit.

I tried searching on the internet but failed to find a solution.

I am using Powershell ISE, Visual Studio 2015 powershell project. Current Powershell version is 5.0

Normal debugging works fine, but as soon as i start some async/multithreaded debugging i.e. using Start-Job i dont see any breakpoint getting hit.

Any help is appreciated.

来源:https://stackoverflow.com/questions/40221641/debug-job-the-job-cannot-be-debugged-because-the-host-debugger-mode-is-set-to-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!