C# 是否使用同一命令运行多个任务?
我想把我在C# 是否使用同一命令运行多个任务?,c#,visual-studio-code,vscode-tasks,C#,Visual Studio Code,Vscode Tasks,我想把我在tasks.json中定义的一些命令/任务链接起来 我有许多不同的子项目(C#csproj文件),它们应该在一个大任务中构建,然后测试(shell命令) 我可以这样做,但我只能逐个调用不同的命令。更新 在得到进一步的澄清之后,可以在VisualStudio中将您要完成的配置为构建后步骤。为将生成的最后一个项目配置命令 原始答案 您可以并行执行任务: public class TaskCollection { public string version { get; set;
tasks.json
中定义的一些命令/任务链接起来
我有许多不同的子项目(C#csproj
文件),它们应该在一个大任务中构建,然后测试(shell命令)
我可以这样做,但我只能逐个调用不同的命令。更新 在得到进一步的澄清之后,可以在VisualStudio中将您要完成的配置为构建后步骤。为将生成的最后一个项目配置命令 原始答案
您可以并行执行任务:
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; }
}
公共类任务集合
{
公共字符串版本{get;set;}
公共列表任务{get;set;}
公共静态void RunTasks()
{
string json=new WebClient()。下载字符串(“https://gist.githubusercontent.com/eppz/f941f2e85e12e7cc81c63ee2ac1354e5/raw/fa15f7b9774083f481504677b96353fe0da777be/tasks.json");
TaskCollection col=new JavaScriptSerializer()。反序列化(json);
Parallel.ForEach(col.tasks,(x)=>
{
执行任务(x);
}
);
}
私有静态void ExecuteTask(任务x)
{
//做点什么
}
}
公开课任务
{
公共字符串taskName{get;set;}
公共bool isBuildCommand{get;set;}
公共字符串命令{get;set;}
公共字符串[]args{get;set;}
公共字符串showOutput{get;set;}
公共字符串问题匹配器{get;set;}
公共布尔ISSHELL命令{get;set;}
公共bool isTestCommand{get;set;}
}
哇,自从1.10以来,有一个dependsOn
属性请参见发行说明中的
{
"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"
}
]
}
你说你只能一个接一个地调用它们是什么意思?你能提供你想要完成的更多细节吗?当然,谢谢你回来。我想按下一个按钮,然后构建6个子项目,然后运行6个测试命令。实际上,仅此而已。是否有方法定义任务依赖项或类似项?您可以在visual studio中将命令添加为生成后步骤。您当前如何调用任务。耶,谢谢,我在这里尝试使用VS代码,而不是Visual Studio(请参阅标记)。哇,您太快了。您可以将此代码放在独立的
.csproj
中,并将其作为任务运行。您可以使用json中的设置来控制它的功能。例如,启动运行单元测试然后返回的进程。单元测试将执行,但VSCode可以继续执行下一个任务,因为它不会等待单元测试完成。很好。他们需要更新他们的文档,因为我在任务文档中没有看到任何关于dependsOn
的内容。这正是我想要的,但你必须以相反的顺序定义你的任务,这有点奇怪。是的,我在GitHub上的一些随机任务中发现了这一点。json
。