windowsmacosvisual-studio-code.net-corelaunch

How to target platforms with launch.json


The omnisharp ReadMe says this:

Operating System Specific Configurations

If there specific commands that need to be changed per operating system, you can use the fields: 'windows', 'osx', or 'linux'. You can replace any of the fields mentioned above for the specific operating system.

This is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
            "args": [
                "c:\\git\\core\\XunitTestLib\\Steps\\",
                // "~/../../XunitTestLib/Steps"
            ],
            "cwd": "${workspaceFolder}/TestConsole",
            "console": "internalConsole",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        },
    ]
}

When debugging I want to builds on Windows to start with the "args" entry which is uncommented, but on mac os I want it to start with the line which is commented out.

I am assuming that I would duplicate the configuration, once for Windows and mac, each, but this statement is confusing:

You can replace any of the fields mentioned above for the specific operating system.

It appears to be saying that I can replace "args" with "osx" but that obviously does not work.

How do I create a configuration for a target platform?


Solution

  • Turns out that targeting multiple platforms is a lot easier than I expected and is explained here with regards to the tasks.json file (but works just the same for launch.json).

    My launch.json file adjusted for osx and windows would look like this:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": ".NET Core Launch (console)",
                "type": "coreclr",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
                "windows": {
                    "args": [
                        "c:\\git\\core\\XunitTestLib\\Steps\\"
                    ]
                },
                "osx": {
                    "args": [
                        "~/../../XunitTestLib/Steps"
                    ]
                },
                "cwd": "${workspaceFolder}/TestConsole",
                "console": "internalConsole",
                "stopAtEntry": false,
                "internalConsoleOptions": "openOnSessionStart"
            },
            {
                "name": ".NET Core Attach",
                "type": "coreclr",
                "request": "attach",
                "processId": "${command:pickProcess}"
            },
        ]
    }