我尝试做一个简单的任务:在 Visual Studio 的帮助下,我尝试获取有关诸如基线之类的任务的信息。我可以阅读并获取所有项目,但无法获取任务列表。我怎样才能得到它?这是我的代码示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ProjectServer.Client;
namespace ProjectAPI
{
class Program1
{
private const string pwaPath = "https://XXXXXXXXX";
private static string projName = string.Empty;
private static ProjectContext projContext;
private static PublishedTask projTasks;
static void Main(string[] args)
{
projContext = new ProjectContext(pwaPath);
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
List<string> TasksID = new List<string>();
foreach (PublishedProject pubProj in projContext.Projects)
{
Console.WriteLine("\n\t{0} : {1}", pubProj.Name, pubProj.CreatedDate.ToString());
foreach (PublishedTask item in pubProj.Tasks)
{
TasksID.Add(projTasks.Name);
}
Console.WriteLine("\nProject ID : Project name : Created date");
}
Console.Write("\nPress any key to exit: ");
Console.ReadKey(false);
}
}
}
之后我有以下错误:
Microsoft.SharePoint.Client.Runtime.dll 中的“Microsoft.SharePoint.Client.CollectionNotInitializedException”
集合尚未初始化。它尚未被请求或请求尚未执行。可能需要明确要求。