2

I want to chain up some commands / tasks I defined in tasks.json.

I have many different sub-projects (C# csproj files) that should be built, then tested (shell commands) in a big single task.

I have this tasks.json working, but I can only invoke the different commands one by one.

5
  • What do you mean you can only invoke them one by one? Can you provide more details of what you are trying to accomplish? Commented Jul 8, 2017 at 1:02
  • Sure, thanks for getting back. I want to press a button, then have my 6 sub-projects built, then have 6 test commands ran. Actually that's all. Commented Jul 8, 2017 at 1:04
  • Is there a way to define a task dependency, or similar? Commented Jul 8, 2017 at 1:08
  • You can add your commands as post build steps in visual studio. How are you invoking your tasks currently. Commented Jul 8, 2017 at 1:12
  • 2
    Yap, thanks, I'm trying to use VS Code here, not Visual Studio (see tags). Commented Jul 8, 2017 at 1:19

2 Answers 2

1

Wow, there is a dependsOn property since 1.10.
See More work on Terminal Runner in release notes.

{
    "version": "2.0.0",
    "tasks":
    [
        {
            "taskName": "Build",
            "isBuildCommand": true,
            "command": "/Applications/Unity/Unity.app/Contents/MonoBleedingEdge/bin/xbuild",
            "args":
            [
                "Project.sln",
                "/property:GenerateFullPaths=true"
            ],
            "showOutput": "silent",
            "problemMatcher": "$msCompile"
        },
        {
            "taskName": "Build EPPZ.Extensions.Test",
            "command": "/Applications/Unity/Unity.app/Contents/MonoBleedingEdge/bin/xbuild",
            "args":
            [
                "Assets/Plugins/eppz!/Extensions/Test.csproj",
                "/property:Configuration=Local",
                "/property:GenerateFullPaths=true"
            ],
            "showOutput": "always",
            "problemMatcher": "$msCompile"
        },
        {
            "taskName": "Test EPPZ.Extensions.Test",
            "isShellCommand": true,
            "command": "mono",
            "dependsOn": [ "Build EPPZ.Extensions.Test" ],
            "args":
            [
                "/Users/eppz/Projects/Unity/Packages/NUnit/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe",
                "bin/EPPZ.Extensions.Test.dll",
                "--labels=All",
                "--result=EPPZ.Extensions.Test.Result.xml"
            ],
            "showOutput": "always"
        },
        {
            "taskName": "Test",
            "isShellCommand": true,
            "isTestCommand": true,
            "command": "echo",
            "args": ["All done."],
            "dependsOn": [ "Test (EPPZ.Extensions.Test)" ],
            "showOutput": "always"
        }
    ]
}
Sign up to request clarification or add additional context in comments.

2 Comments

Good find. They need to update their docs because I don't see any mention of dependsOn in the documents for tasks. This is exactly what I was looking for, but it is kind of odd that you have to essentially define your tasks in reverse order.
Yeah, I spotted this on GitHub in some random tasks.json somewhere.
0

Update

After getting further clarification, what you are trying to accomplish can be configured as post build steps in Visual Studio. Configure the commands for the last project that will build.

enter image description here

Original Answer


You can execute your tasks in parallel:

public class TaskCollection
{
    public string version { get; set; }
    public List<Task> tasks { get; set; }
    public static void RunTasks()
    {
        string json = new WebClient().DownloadString("https://gist.githubusercontent.com/eppz/f941f2e85e12e7cc81c63ee2ac1354e5/raw/fa15f7b9774083f481504677b96353fe0da777be/tasks.json");
        TaskCollection col = new JavaScriptSerializer().Deserialize<TaskCollection>(json);
        Parallel.ForEach(col.tasks, (x) =>
        {
            ExecuteTask(x);
        }
        );
    }

    private static void ExecuteTask(Task x)
    {
        //Do something
    }
}

public class Task
{
    public string taskName { get; set; }
    public bool isBuildCommand { get; set; }
    public string command { get; set; }
    public string[] args { get; set; }
    public string showOutput { get; set; }
    public string problemMatcher { get; set; }
    public bool isShellCommand { get; set; }
    public bool isTestCommand { get; set; }
}

3 Comments

Wow, you're fast. 😀 I was thinking about this as an option, as I could hook up any command in a .csproj file, but I'd like to specify this in VS Code to have things organized / explicit.
You could put this code in a standalone .csproj and run it as a task. You can use the settings from your json to control what that does. For example, start a Process that runs a unit test and then returns. Your unit test will execute but VSCode can continue on to its next task because it is not waiting for your unit tests to complete.
what is this visual studio answer doing here with a question about visual studio code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.