I'm using VS Code with php-debug extension, IIS Express and PHP (IIS/PHP from Web PI) and trying to automate IIS Express startup with a preLaunchTask on launch.json file from Visual Studio Code. So I wrote those things below on my launch.json and tasks.json files.
All things work nicely, except for the fact that VS Code keeps locked on IIS Startup, because IIS stay running, waiting for the user input (i.e.: "Q" to quit IIS). This way, even with IIS running ok, I couldn't debug inside VS Code, because it's waiting the IIS task to finish.
I've tried with Powershell and Start-Job (PS script excerpt below) without success, because PowerShell seems to start IIS, but nothing happens (IIS is not started).
How could I accomplish that? Where I'm doing it wrong? Thank you in advance.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000, "preLaunchTask": "start_server"
}
]
}
tasks.json -- cmd version
{
"version": "0.1.0",
"command": "cmd.exe",
"isShellCommand": true,
"args": [
"/C",
"runphp.cmd"
],
"tasks": [
{
"taskName": "start_server",
"isBuildCommand": false,
"showOutput": "always"
}
]
}
tasks.json -- Powershell version
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"-ExecutionPolicy",
"ByPass",
"-File",
".\\wahoo.ps1" // my powershell script
],
"tasks": [
{
"taskName": "start_server",
"isBuildCommand": false,
"showOutput": "always"
}
]
}
wahoo.ps1 -- only used when I set the powershell version from tasks.json
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$command = @'
cd $scriptDir | cmd.exe /C runphp.cmd
'@
Start-Job -Name "IISPHP" -Arg $command -ScriptBlock {
param ($command)
Invoke-Expression -Command:$command
Start-Sleep 3
}
My runphp.cmdis an adapted version of the original runphp.cmd from IIS/PHP installation folder to suit my needs and contains the following:
runphp.cmd
SET pf=%ProgramFiles%
if DEFINED ProgramFiles(x86) SET pf=%ProgramFiles(x86)%
set appcmd="%pf%\iis express\appcmd.exe"
set iisexpress="%pf%\iis express\iisexpress.exe"
cd > tmpFile
set /p currentdir= < tmpFile
del tmpFile
where php-cgi.exe > tmpFile
set /p phprt= < tmpFile
del tmpFile
if DEFINED phprt goto setup_iis
SET phprt=%pf%\PHP\v5.3\php-cgi.exe
:setup_iis
%appcmd% set config /section:system.webServer/fastCgi "/+[fullPath='%phprt%']" "/apphostconfig:%currentdir%\applicationhost.config"
%appcmd% set config /section:system.webServer/handlers "/+[name='PHP-FastCGI',path='*.php',modules='FastCgiModule',verb='*', scriptProcessor='%phprt%',resourceType='Either']" "/apphostconfig:%currentdir%\applicationhost.config"
%iisexpress% /site:EmptySite /config:"%currentdir%\applicationhost.config"