Handling Task Constraints

Working with Constraints

The ConstraintDate and ConstraintType properties are exposed by the Task class to handle constraints:

  • ConstraintDate accepts and returns the Date data type.
  • ConstraintType accepts and returns one of the values of the ConstraintType enumeration.

Setting Constraints in Microsoft Project

To set constraints in Microsoft Project:

  1. On the View menu, select More Views and then Task Entry Form.
  2. Double click a task on the Task Entry Form.
  3. Select the Advance tab.
  4. Set a constraint by selecting an option from the Constraint type list and a date for the Constraint date list.

Setting constraints in Microsoft Project

updating task constraints in Microsoft Project

Setting Constraints with Aspose.Tasks

The constraint date is NA when the constraint type is As Soon As Possible or As Late As Possible. For date values equal to NA, Aspose.Tasks uses the value “1/1/2000” in the evaluation version, and DateTime.MinValue for the licensed product. In the below case, we take a source project file as an input and apply different types of constraints on various tasks in each case. The following code samples show the application of different Constraint types and the accompanied snapshot of the result for each case.

The input file

edit MPP file with task constraints in Microsoft Project

The code samples below set the constraint type set to Start No Earlier Than.

Output file with Start No Earlier Than constraint

save MPP file with task constraints in Microsoft Project

The code samples below set the constraint type set to Finish No Earlier Than.

Output file showing Finish No Earlier Than constraint

Finish No Earlier Than task constraint in Microsoft Project

The code samples below set the constraint type set to Must Start On.

Output file showing Must Start On constraint

Must Start On task constraint in Microsoft Project

The code samples below set the constraint type set to As Late As Possible.

Output file showing As Late As Possible constraint

As Late As Possible task constraint in Microsoft Project

The code sample below shows the constraint type set to Must Finish On.

Output file showing Must Finish On constraint

Must Finish On task constraint in Microsoft Project

Getting Constraints

This code sample displays any constraints found when traversing the tasks in the project to a command window.