How to debug a Cake file using Visual Studio Code

As you might already know, debugging Cake scripts using Visual Studio has been supported since the v0.12.0 release of Cake. But since the v0.16.1 release of Cake, thanks to porting Cake to .NET Core, it is now also possible to debug Cake files using Visual Studio Code.

What does this mean?

This means that while creating/modifying your Cake build script, you can use Visual Studio Code to step into the Cake file and get full debug support regardless of which operating system you are running (Windows / Linux / Mac).

How does this work?

In order to enable debugging of a Cake file using Visual Studio Code, follow these steps:

  1. Install Cake.CoreCLR NuGet package to your tools folder
  2. Install Cake Extension for Visual Studio Code
  3. Set up .NET Core debugger in Visual Studio Code. See http://aka.ms/vscclrdebugger for details
  4. Open the directory containing your Cake files in Visual Studio Code
  5. Create file .vscode/launch.json and add the following content (assuming your Cake file is build.cake)
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": ".NET Core Launch (console)",
                "type": "coreclr",
                "request": "launch",
                "program": "${workspaceRoot}/tools/Cake.CoreCLR/Cake.dll",
                "args": [
                    "${workspaceRoot}/build.cake",
                    "--debug",
                    "--verbosity=diagnostic"
                ],
                "cwd": "${workspaceRoot}",
                "stopAtEntry": true,
                "externalConsole": false
            }
        ]
    }
  6. Open your Cake file and add a breakpoint by hitting F9
  7. Hit F5 to start debugging
    Debugging

Alternative Approach

Another way to enable debugging of a Cake script is to start Cake from the commandline and then attach the debugger from within Visual Studio Code. This can be done using the following steps:

  1. Add the following configuration to the .vscode/launch.json file that you created in the previous steps
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command.pickProcess}"
    }
  2. Open your Cake file and add a breakpoint by hitting F9
  3. Select the configuration you added in the previous step
    Select config
  4. Open terminal and run
    dotnet tools/Cake.CoreCLR/Cake.dll build.cake --debug
  5. Hit F5 and select the process from the drop-down list
    Select process

Example Code

A working example can be found here

Cake for Visual Studio released

I am very proud to announce the first release of the Cake for Visual Studio extension for Visual Studio 2015. This extension brings full syntax highlighting, integration with the Task Runner Explorer, special commands to get you started with Cake on new projects and new templates.

Read more...

Cake v0.16.1 released

Version 0.16.1 of Cake has been released.

Following the release of Cake v0.16.0 last week, mholo65 identified an issue with debugging in Visual Studio Code. In addition, we also noticed that we were missing some properties in the generated assemblies.

As a result, v0.16.1 of Cake is now available.

Please let us know if you run into any issues with this latest release.

Full details of everything that was included in this release can be seen below.

Read more...

Announcing Cake for Yeoman

Announcing Cake for Yeoman

Yeoman users rejoice! You can now bootstrap your project for Cake with Yeoman and the new generator-cake generator.

Read more...

Cake v0.16.0 released

Version 0.16.0 of Cake has been released, and it's a big release!

Not only are we supporting the full .NET framework (v4.5), but from this version we will also support running Cake on platforms capable of running .NET Core (netstandard1.6).

For this to work, you will have to install the Cake.CoreCLR package instead of the normal Cake package. A blog post describing this more in detail will be published soon.

Please let us know if you run into any issues with this latest release.

Contributions were included from:

Full details of everything that was included in this release can be seen below.

Read more...