Skip to main content

.NET Debugging

Raftt supports interactive .NET debugging using JetBrains Rider. Support for VS Code is coming soon!

To debug with Raftt, you must first install Raftt's IDE plugin. See here for installation instructions.

Configuration

To configure .NET debugging you need to define two things -

  1. Where and when to compile your .NET binary
    1. Add a builder container to the workload
    2. Define a before launch task
  2. Create a run/debug configuration

Add a builder container

The best way to let your env compile .NET binaries without modifying your application container is by adding a builder container to the pod. This can be easily defined in your .raftt file. Here you can see the configuration for adding a builder container to the cart service of our sample project -

cart = resources.deployments["cart"]

# Define the container and add it to the workload
builder = Container(yaml="""
name: builder
image: mcr.microsoft.com/dotnet/sdk:7.0.201
workingDir: /src
""")
cart.spec.template.spec.containers.append(builder)

# Mount the source code and the compiled artifact folder to
# both the application container and the builder container
cart_out = volume("cart-out")
cart.mount(repo_root.subpath("src/cartservice/src"), "/src", container="builder")
cart.mount(repo_root.subpath("src/cartservice/src"), "/src")
cart.mount(cart_out, "/tmp/out", container="builder")
cart.mount(cart_out, "/app", init_on_rebuild=True)

Create a run/debug configuration

To debug with Raftt, define a run/debug configuration of the type .NET Executable with Raftt. Its fields are equivalent to a standard .NET run/debug config. The main difference is that with Raftt, the Executable Path parameter doesn't refer to a file that exists locally, but to a file inside the debugged workload. It should contain the path of the artifact created by the compilation (see below for the compilation definition). Then, add a single env var called RAFTT_WORKLOAD stating the workload to debug.

Here you can see the configuration for the cart service of our sample project -

.NET Executable with Raftt run/debug config in Rider

Debugging a sidecar container

To debug a sidecar container, add an additional env var - RAFTT_CONTAINER, whose value is the debugged container name. If not stated, the selected container is the workload's main container - either the one annotated as default, or if no container is annotated - the first one in the manifest.

Create a before launch task

To recompile your code before every run/debug session, you need to define a before launch task in you debug configuration. Create a task of the type Run on Raftt Workload and define what build script to run and where -

Run on Raftt Workload before launch task on Rider

The command is dotnet publish cartservice.csproj -c debug -o /tmp/out

tip

To easily share your run/debug configuration with the rest of the team, mark the "store as project file" checkbox and commit the new file, typically located under .run, to the repo.