运行 多个任务使用同一个命令?

Run multiple tasks with the same command?

我想链接一些我在tasks.json中定义的命令/任务

我有许多不同的子项目(C# csproj 文件)应该构建,然后在一个大的任务中测试(shell 命令)。

我有这个 tasks.json 工作,但我只能一个接一个地调用不同的命令。

更新

在得到进一步说明后,您要完成的工作可以配置为 Visual Studio 中的 post 个构建步骤。为将构建的最后一个项目配置命令。

原答案


您可以并行执行任务:

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; }
}

哇,从 1.10 开始就有了 dependsOn 属性。
请参阅发行说明中的​​ More work on Terminal Runner

{
    "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"
        }
    ]
}