Skip to content

Predefined task customization

Nikita Romanov edited this page Feb 7, 2023 · 5 revisions

Сustomize the Default Build Task

To customize the default build task, preform the following steps:

  1. In the VSCode, open command palette (ctrl + shift + P on Windows/Linux, command + shift + P on MacOS).

  2. In the opened panel, type in the Configure Default Build Task:

  3. Select dotnet-meteor: Build from the list:

    This will add the tasks.json file to your project:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "type": "dotnet-meteor.task",
                "target": "Build",
                "problemMatcher": [],
                "label": "dotnet-meteor: Build",
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
  4. Specify a custom pre-build parameter in the args section of the tasks.json file.

    "type": "dotnet-meteor.task",
    "target": "Build",
    "problemMatcher": [],
    "label": "dotnet-meteor: Build",
    "args": [
        "-p:MyCustomBuildOption=value"
    ],
    "group": {
        "kind": "build",
        "isDefault": true
    }

    You can also change the target property value to Publish. In this case, before running the application, dotnet will run the publish command instead of the build. It is similar to the Visual Studio's Publish build configuration.

Create Multiple Tasks

You can duplicate the default build task and change any of the task setting. The following code snippet contains the default and custom publish tasks:

{
	"version": "2.0.0",
	"tasks": [
	    {   //Default build task
		"type": "dotnet-meteor.task",
		"target": "Build",
		"problemMatcher": [],
		"label": "dotnet-meteor: Build",
		"group": {
			"kind": "build",
			"isDefault": true
		}
	    },
            {   //Custom publish task
		"type": "dotnet-meteor.task",
		"target": "Publish",
		"problemMatcher": [],
                "args": [ "-p:MyReleaseProperty=value" ],
		"label": "Custom publish task"
	    }
	]
}

To run the custom build task, type in the Run Task in the VSCode command palette, and choose the task:

Customize preLaunchTask

  1. Create the launch.json file. The following code sample contains its default content:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": ".NET Meteor Debugger",
                "type": "dotnet-meteor.debugger",
                "request": "launch",
                "preLaunchTask": "dotnet-meteor: Build"
            }
        ]
    }
  2. You can set the preLaunchTask's value to your task's name. The following code sample defines a new task in the tasks.json file:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "type": "dotnet-meteor.task",
                "target": "Build",
                "problemMatcher": [],
                "label": "My custom task",
                "args": [ "-p:MyCustomProperty=value" ],
            }
        ]
    }
  3. Now you can register this task in the launsh.json file to run it before the application startup:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": ".NET Meteor Debugger",
                "type": "dotnet-meteor.debugger",
                "request": "launch",
                "preLaunchTask": "My custom task"
            }
        ]
    }
  4. Optional step. You can remove the preLaunchTask parameter and build the project only when you call the build command:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": ".NET Meteor Debugger",
                "type": "dotnet-meteor.debugger",
                "request": "launch"
            }
        ]
    }

Create Multiple Launch Cnfigurations

You can lanch multiple launch configurations for different run scenarios:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Meteor (no build)",
            "type": "dotnet-meteor.debugger",
            "request": "launch"
        },
        {
            "name": ".NET Meteor (custom build)",
            "type": "dotnet-meteor.debugger",
            "request": "launch",
            "preLaunchTask": "My custom task"
        },
        {
            "name": ".NET Meteor (pair to Mac)",
            "type": "dotnet-meteor.debugger",
            "request": "launch",
            "preLaunchTask": "My custom task 2"
        }
    ]
}

Open the side bar's Run and debug tab and select a launch configuration from the drop-down list:

Clone this wiki locally