I have the following code that updates certain task fields. The problem with this code is that I have to publish an entire project after updating each task one-by-one. So for example, if I had 500 tasks to update, the project would have to be published 500 times. As you can see, this is completely overkill, slow and unnecessary.
using (ProjectContext projectContext = GetClientContext(psCred))
{
projectContext.Load(projectContext.Projects);
projectContext.ExecuteQuery();
foreach (var project in projectContext.Projects)
{
var draftProject = project.CheckOut();
projectContext.Load(draftProject.Tasks);
projectContext.ExecuteQuery();
projectContext.Load(draftProject.Task);
projectContext.ExecuteQuery();
foreach (var task in draftProject.Tasks)
{
task["FIELD"] = "VALUE";
var job = draftProject.Update();
projectContext.WaitForQueue(job, int.MaxValue);
job = draftProject.Publish(true);
projectContext.WaitForQueue(job, int.MaxValue);
}
}
}
I hope there is a way to update update all of the project tasks at once with only one publish at the end just like how Microsoft Project desktop application does it.