Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Tutorial for debugging .NET applications

February 22, 2022
Tom Deseyn
Related topics:
.NETContainersIDEs
Related products:
Red Hat Enterprise Linux

    A previous article showed how to debug a .NET application that is running on Kubernetes from Visual Studio Code (VS Code) on your local development machine. In this tutorial, you'll debug an application that is running in a container right on your development machine.

    Use cases

    If you plan to deploy your application on Kubernetes, the application will run in a container. Debugging the application in a local container can let you see its behavior in a local environment that is fairly close to the production environment.

    Even when you don't intend to deploy your application using containers, running it in a container can be a way to reproduce a bug that is reported to occur only in a specific environment, such as a specific Linux distribution.

    Choices for building an image

    The image for our debug session needs to provide .NET runtime dependencies. You can build an image yourself or base it on images provided by Microsoft (through runtime images or SDK images) or Red Hat (through runtime images or SDK images).

    Red Hat provides Universal Base Images (UBI) for .NET. These are enterprise-grade images that can be freely distributed and deployed anywhere. Take a look at the UBI FAQ or read the e-book Red Hat Universal Base Images (UBI) to learn more.

    Prerequisites

    If you haven't already, install Visual Studio Code using the instructions on the project's website.

    Next, launch VS Code and install the C# extension and Docker extension.

    You also need to install a container engine such as Docker or Podman. I'm using Podman, which comes pre-installed on Fedora. The VS Code Docker extension doesn't detect Podman automatically, though. The rest of this section shows how you can configure the use of Podman. If you are using Docker, you can skip to the next section.

    First, enable the podman.socket service, which provides a Docker-compatible API:

    $ sudo dnf install podman-remote
    $ systemctl --user enable --now podman.socket

    In VS Code, open the Command Palette by pressing Ctrl+Shift+P and choose Preferences: Open Settings (JSON).

    Add the following settings:

    {
      "docker.dockerPath": "podman",
      "docker.host": "unix:///run/user/1000/podman/podman.sock"
    }

    The first setting tells the extension to use the podman executable instead of docker. The other setting provides the path to the API socket. The value 1000 needs to match your user ID (UID). You can see your UID by running id -u.

    Debug the application

    Open your application folder in VS Code. If you don't have an application, you can create one as follows:

    $ dotnet new web -o web
    $ cd web
    $ code .

    Now open the Command Palette by pressing Ctrl+Shift+P and choose Docker: Add Docker Files to Workspace.... (Figure 1).

    The Command Palette in VS Code, with the proper extensions, lets you add Docker or Podman files.
    Figure 1. The Command Palette in VS Code, with the proper extensions, lets you add Docker or Podman files.

    The IDE prompts you with some questions:

    1. As the application platform, choose .NET ASP.NET Core.
    2. When prompted to select an operating system, pick your host OS (Windows/Linux).
    3. Next, specify a comma-separated list of ports to expose. I suggest specifying 5000,8080 because those are the ports used by the Microsoft and Red Hat images.
    4. Finally, answer No when asked to add the optional Docker Compose file.

    The IDE will add a debug configuration to .vscode/launch.json to launch the application in a container. The .vscode/tasks.json file contains a few tasks that are used in this process:

    • The docker-run: debug task launches the container.
    • The docker-build: debug task builds the container.
    • The usual build task builds the application on the host.

    The docker-build step uses the Dockerfile that was added to the workspace. The base image defined in this file is used for debugging. Change the configuration to use a UBI image by replacing all the lines starting with the FROM … as build line with the following:

    FROM registry.access.redhat.com/ubi8/dotnet-60-runtime AS base

    If you're not using .NET 6.0, you need to update the FROM image so it provides the right version.

    If you are using the Red Hat image for an earlier .NET version than 6.0, you need to add the following additional line:

    CMD [ "bash" ]

    You can now launch your application In VS Code's Run and Debug tab. Choose the Docker .NET Core Launch option (Figure 2).

    The Run and Debug tab in VS Code lets you run your application.
    Figure 2. The Run and Debug tab in VS Code lets you run your application.

    The application will launch in the container with the debugger attached. You can add a breakpoint and hit it in the debugger (Figure 3).

    The VS Code debugger has stopped the application at a breakpoint.
    Figure 3. The VS Code debugger has stopped the application at a breakpoint.

    Conclusion

    VS Code is designed for .NET and is extremely valuable for developing and debugging .NET applications. It saves a lot of time if you can debug in similar ways on your local system and in the cloud, running your application in a container in both cases. This approach helps you achieve that flexibility.

    Last updated: June 3, 2024

    Related Posts

    • Three ways to containerize .NET applications on Red Hat OpenShift

    • Set up continuous integration for .NET Core with OpenShift Pipelines

    • Use VS Code to debug .NET applications

    Recent Posts

    • Red Hat Enterprise Linux 10.2 and 9.8: Top features for developers

    • What GPU kernels mean for your distributed inference

    • Debugging image mode with Red Hat OpenShift 4.20: A practical guide

    • EvalHub: Because "looks good to me" isn't a benchmark

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.