我希望链接一些命令/任务我在tasks.json
中定义。
我有许多不同的子项目(C#csproj
文件)应该构建,然后在一个大的单个任务中测试(shell命令)。
我有tasks.json
工作,但我只能逐个调用不同的命令。
答案 0 :(得分:1)
<强>更新强>
在进一步说明之后,您要完成的任务可以配置为Visual Studio中的后期构建步骤。配置将要构建的最后一个项目的命令。
原始答案
您可以并行执行任务:
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 :(得分:1)
哇,自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"
}
]
}