Working with Tasks in .NET
Managing task actual properties is an essential part of project scheduling and reporting. In Aspose.Tasks for .NET, you can easily read a task’s actual cost, duration, start/finish dates, overtime work, and more. This allows developers to analyze project progress programmatically, without relying on Microsoft Project.
What Are Actual Properties?
Actual properties help you find out how much work, time, or money has already been spent on a task. These values are especially useful for comparing planned vs. actual progress.
Common Actual Properties
The static class Tsk exposes the following fields:
- ActualCost → task’s actual cost (
double
) - ActualOvertimeCost → overtime cost (
double
) - ActualOvertimeWork → overtime work (
TimeSpan
) - ActualDuration → actual duration (
TimeSpan
) - ActualStart → when the task actually started (
DateTime
) - ActualFinish → when the task actually finished (
DateTime
) - ACWP → Actual Cost of Work Performed (
double
)
Viewing Actual Properties in Microsoft Project
If you want to compare values inside MS Project:
- Open the View menu → select More Views → choose Task Entry.
- On the Insert menu → select Column → add fields like Actual Start, Actual Finish, Actual Work, etc.
This way, you can visually verify the same data that Aspose.Tasks API provides programmatically.
Reading Actual Properties in C#
Below is a sample that loads a project file (.mpp
) and prints actual task properties to the console.
1// Create Project instance
2Project project = new Project("New Project.mpp");
3
4// Create a ChildTasksCollector instance
5ChildTasksCollector collector = new ChildTasksCollector();
6
7// Collect all the tasks from RootTask using TaskUtils
8TaskUtils.Apply(project.RootTask, collector, 0);
9
10// Parse through all the collected tasks
11foreach (Task task in collector.Tasks)
12{
13 Console.WriteLine("Task Name : " + task.Get(Tsk.Name));
14 Console.WriteLine("Actual Start: " + task.Get(Tsk.ActualStart).ToLongDateString());
15 Console.WriteLine("Actual Finish: " + task.Get(Tsk.ActualFinish).ToLongDateString());
16 Console.WriteLine("Actual Duration: " + task.Get(Tsk.ActualDuration).TimeSpan.Hours.ToString());
17 Console.WriteLine("Actual Cost: " + task.Get(Tsk.ActualCost).ToString());
18 Console.WriteLine("---------------------------------------------");
19}
Tip: You can use
ChildTasksCollector
with
TaskUtils
to recursively fetch all tasks from the root task.
Key Benefits
- Automates project reporting without opening Microsoft Project.
- Allows exporting actuals to dashboards, Excel, or databases.
- Works with
.mpp
and other supported formats.
FAQ
Q: Do I need Microsoft Project installed to read Actual Properties?
- No. Aspose.Tasks for .NET works independently of Microsoft Project.
Q: Can I update Actual Properties programmatically?
- Yes. You can set values for
ActualStart
,ActualFinish
, and others before saving the project.
Q: Does this work with Primavera or only MS Project?
- Aspose.Tasks supports multiple formats, but Actual Properties are primarily aligned with Microsoft Project fields.