Debug NX Open in VS Code

James Lindsey at Ecology of Commanster, CC BY-SA 2.5, via Wikimedia Commons

Table of Contents

Background

In another article, I showed how NX Open programs can be created and compiled with the source code editor VS Code (Visual Studio Code)1.

A debugger is an important tool for program development and troubleshooting. VS Code and the C# extension primarily target .NET Core and not the .NET Framework required for NX Open development. Nevertheless, .NET Framework applications can also be debugged2.

Requirements

The procedure described here is only suitable for debugging compiled NX Open applications. Debugging journals3 is not possible with VS Code.

Setting up the development environment is described in 1.

Configure the NX Open Project

First, the project file *.csproj must be adapted. PlatformTarget must be x64 and the DebugType must be portable.

...
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
    <PlatformTarget>x64</PlatformTarget><!-- To enable debugging with vs code-->
    <DebugType>portable</DebugType><!-- To enable debugging with vs code-->
 </PropertyGroup>
...

Create Start Configuration

To create a debug configuration, a corresponding entry must be added to the launch.json file. If this file does not yet exist, it must be created in the .vscode directory (see e.g. 4).

Debug Configuration in launch.json.
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to process",
            "type": "clr",
            "request": "attach",
            "processId" : "${command:pickProcess}"
        }
    ],
    "compounds": []
}

Debuggen

First, NX must be started. Then the debug session can be launched in VS Code with F5 and the NX process can be selected.

Start Debug Session

When executing the NX Open application, the program stops at a breakpoint.

Breakpoint in C# Code.

  1. NX Open und VS Code: https://www.ib-boettcher.de/en/post/nxopen-vscode/ ↩︎ ↩︎

  2. Desktop .NET Framework: https://github.com/OmniSharp/omnisharp-vscode/wiki/Desktop-.NET-Framework ↩︎

  3. The term journal is often used in a broader sense for NX Open programs in general. Here, however, it is used only for programs implemented in VB.NET or C # that are executed directly from source code. ↩︎

  4. stackoverflow, feO2x: https://stackoverflow.com/a/53271098 ↩︎

Related