Wednesday, May 27, 2015

Run PHP from Visual Studio Code

In my previous posts I explained examples using a solution file to compile and debug .NET (mono) in Visual Studio Code.

This post shows how to set up a task to run PHP using the build in Development Server of PHP.

In Visual Studio Code open the folder with the php file(s).

Then start the Command Palette and choose Configure Task Runner.
This creates a tasks.son file. Clear all and replace with the settings below:

{
"version": "0.1.0",
"command": "php",
"args": [
"-S", "127.0.0.1:8080",
"-t", "${workspaceRoot}"
]
}

Save the file and start the task from the Command Palette, choose Run Task and then 'php'.

A PHP Development Server has been started on port 8080. Start your browser, go to http://127.0.0.1:8080 and you will see the website from the selected folder.



At this moment it is not possible to debug PHP from Visual Studio Code.

Wednesday, May 06, 2015

Debug a Visual Studio solution in Visual Studio Code on OSX

In my previous post I showed how to compile a .NET solution with Visual Studio Code with Mono on a Mac. This post shows how to set up debugging with Visual Studio Code with Mono on a Mac.

After the solution is build set a breakpoint in de code go to the 'Debug'-panel and press the green play-button in top. It will create a file named launch.json. This file is configured for node, but with some minor adjustments it can work for mono as well.

{
  "version": "0.1.0",
  "configurations": [
    {
      // Name of configuration;
      "name": "Hello",
      // Type of configuration.
      "type": "mono",
      // Workspace relative or absolute path to the program.
      "program": "bin/Debug/Hello.exe",
      // Automatically stop program after launch.
      "stopOnEntry": true,
      // Command line arguments passed to the program.
      "args": [],
      // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
      "cwd": ".",
      // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
      "runtimeExecutable": null,
      // Environment variables passed to the program.
      "env": { }
    }, 
    {
      "name": "Attach",
      "type": "mono",
      // TCP/IP address. Default is "localhost".
      "address": "localhost",
      // Port to attach to.
      "port": 5858
    }
  ]
}

Save the file and you are ready to go!