重要な道を読む
重要なパスは、最小プロジェクト期間を決定するタスクのシーケンスです。このパスのタスクが遅れている場合、プロジェクトのタイムライン全体が影響を受けます。この記事では、 VSTOと ASOPSE.TASKS for .NETの両方を使用して、Microsoftプロジェクトファイルから重要なパスを読む方法を示しています。
導入
プロジェクトのスケジューリングでは、重要なパスは、プロジェクトの終了日に直接影響するタスクを表すため、追跡することが不可欠です。これらのタスクを特定して監視することにより、プロジェクトマネージャーは、遅延を防ぐためにリソースと努力を集中できます。
プログラムでクリティカルパスを取得すると、特にプロジェクトの報告、監視の進捗状況、または早期警告の実装を自動化する場合、動的なプロジェクト分析が可能になります。
VSTOを使用して重要なパスを読んでください
次の手順は、Microsoft Project Interop(VSTO)を使用して重要なタスクを取得する方法を示しています。
- Visual Studioで新しいプロジェクトを作成します。
- comタブからMicrosoft Project 12.0オブジェクトライブラリへの参照を追加します。
microsoft.office.interop.msproject
ネームスペースをインポートします。- 次のコードの例を使用して、クリティカルパスにアクセスします。
1Application projectApplication = new ApplicationClass();
2object missingValue = System.Reflection.Missing.Value;
3
4// Load the project file
5projectApplication.FileOpenEx(@"C:\Project1.mpp",
6 missingValue, missingValue, missingValue, missingValue,
7 missingValue, missingValue, missingValue, missingValue,
8 missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
9 missingValue, missingValue, missingValue, missingValue,
10 missingValue);
11
12Project project = projectApplication.ActiveProject;
13
14// Iterate over tasks and identify critical ones
15foreach (Task task in project.Tasks)
16{
17 if (task != null && (bool)task.Critical)
18 {
19 Console.WriteLine($"Task ID: {task.ID} - {task.Name}");
20 Console.WriteLine($"Start: {task.Start}");
21 Console.WriteLine($"Finish: {task.Finish}\n");
22 }
23}
24
25// Properly close the application without saving changes
26projectApplication.FileCloseAll(PjSaveType.pjDoNotSave);
Notes
- The
Critical
property identifies whether a task is on the critical path. - COM-based interop requires Microsoft Project to be installed on the machine.
- Proper resource management and cleanup are necessary to prevent memory leaks.
Read the Critical Path Using Aspose.Tasks for .NET
Aspose.Tasks for .NET provides a managed, dependency-free approach to reading critical path data:
- Create a .NET project.
- Add a reference to the Aspose.Tasks assembly.
- Import the
Aspose.Tasks
namespace. - Use the code snippet below to read critical tasks.
1Project project = new Project("New Project.mpp");
2
3// Get the critical path
4TaskCollection criticalPath = project.CriticalPath;
5
6// Enumerate the tasks in the critical path
7foreach (Task task in criticalPath)
8{
9 Console.WriteLine(task.Get(Tsk.Id) + " " + task.Get(Tsk.Name));
10 Console.WriteLine(task.Get(Tsk.Start));
11 Console.WriteLine(task.Get(Tsk.Finish));
12}
ハイライト
- タスクは
project.RootTask.Children
コレクションから取得されます。 - 各タスクは
task.Get(Tsk.IsCritical)
を使用してクリティカルかどうかを判断できます。 - 実行時に Microsoft Project に依存する必要はありません。
比較
機能 | VSTO / 相互運用性 | Aspose.Tasks for .NET |
---|---|---|
Microsoft Project が必要 | ✅ はい | ❌ いいえ |
プラットフォーム依存性 | 🖥 Windows のみ | ✅ クロスプラットフォーム |
展開の複雑さ | ❌ 高 (COM/Office への依存) | ✅ 低 (マネージ DLL) |
クリティカル パスへのアクセス | task.Critical | task.Get(Tsk.IsCritical) |
自動化/サーバーアプリでの使用 | ⚠️ 制限あり | ✅ 推奨 |
概要
プロジェクトファイルからクリティカルパスを理解し、読み取ることで、開発者やアナリストはインテリジェントな計画・追跡ツールを構築できます。VSTO は COM 経由でのアクセスが可能ですが、その制限により、サーバーサイド自動化やクラウド展開といった最新の環境には適していません。
Aspose.Tasks for .NET は、.NET 対応のあらゆる環境で動作する直感的なオブジェクト指向 API により、クリティカルパス分析を簡素化します。エンタープライズクラスのプロジェクト管理アプリケーションに最適です。
その他の機能については、以下をご覧ください。