C# 从Project Online获取ProjectSiteUrl不起作用

C# 从Project Online获取ProjectSiteUrl不起作用,c#,csom,project-online,C#,Csom,Project Online,我编写了以下代码以从project Online中发布的项目中获取ProjectSiteUrl属性 using (ProjectContext projContext = new ProjectContext(pwaUrl)) { using (SecureString securePassword = new SecureString()) { Helper.GetSecurePassword(projContext, securePassword, email

我编写了以下代码以从project Online中发布的项目中获取
ProjectSiteUrl
属性

using (ProjectContext projContext = new ProjectContext(pwaUrl))
{
    using (SecureString securePassword = new SecureString())
    {
        Helper.GetSecurePassword(projContext, securePassword, emailID, password);

        for (int i = 0; i < listGuid.Count; i++)
        {
            #region Load Project
            string spoGuid = listGuid[i].ProjectGuid;

            if (!string.IsNullOrEmpty(spoGuid))
            {


                Guid id = Guid.Parse(spoGuid);

                var projBlk = projContext.LoadQuery(
                        projContext.Projects
                        .Where(p =>
                            p.Id == id
                        )
                        .Include(p => p.Id,
                        p => p.Tasks,
                        p => p.TaskLinks,
                        p => p.ScheduledFromStart,
                        p => p.ProjectSiteUrl,
                            p => p.Name,
                            p => p.IncludeCustomFields,
                            p => p.IncludeCustomFields.CustomFields,
                            P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
                                lu => lu.LookupTable,
                                lu => lu.LookupEntries,
                                lu => lu.LookupEntries.IncludeWithDefaultProperties(
                                    entry => entry.FullValue,
                                    entry => entry.InternalName)
                            )
                        )
                    );

                projContext.ExecuteQuery();

                poFieldValues.Add(LoadProjectsinPO(projBlk, projContext));

            }
            #endregion
            //if (i > 5)
            //{
            //    break;
            //}
            if (i % 5 == 0)
            {
                Thread.Sleep(sleepDelay);
            }
        }
    }
}
使用(ProjectContext projContext=newprojectcontext(pwaul))
{
使用(SecureString securePassword=new SecureString())
{
GetSecurePassword(projContext、securePassword、emailID、password);
for(int i=0;i
p、 Id==Id
)
.包括(p=>p.Id,
p=>p.任务,
p=>p.TaskLinks,
p=>p.ScheduledFromStart,
p=>p.ProjectSiteUrl,
p=>p.Name,
p=>p.IncludeCustomFields,
p=>p.IncludeCustomFields.CustomFields,
P=>P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
lu=>lu.LookupTable,
lu=>lu.LookupEntries,
lu=>lu.LookupEntries.IncludeWithDefaultProperties(
entry=>entry.FullValue,
entry=>entry.InternalName)
)
)
);
projContext.ExecuteQuery();
添加(LoadProjectsinPO(projBlk,projContext));
}
#端区
//如果(i>5)
//{
//中断;
//}
如果(i%5==0)
{
睡眠(睡眠延迟);
}
}
}
}
在尝试访问ProjectSiteUrl属性时,我得到了
null
。我曾经得到正确的ProjectSiteUrl,但最近几周我得到了空值。代码没有更改


我们在Project Online中访问此属性的方式是否发生了变化?

我已经修改了加载查询中加载属性的顺序,并且
ProjectSiteUrl
现在可以加载了。但我不知道为什么它会起作用。如果有人能解释一下,我将不胜感激

 var projBlk = projContext.LoadQuery(
                        projContext.Projects
                        .Where(p =>
                            p.Id == id
                        )
                        .Include(p => p.Id,
                        p => p.ProjectSiteUrl, // Moved ProjectSiteUrl as second loading parameter.
                        p => p.Tasks,
                        p => p.TaskLinks,
                        p => p.ScheduledFromStart,

                            p => p.Name,
                            p => p.IncludeCustomFields,
                            p => p.IncludeCustomFields.CustomFields,
                            P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
                                lu => lu.LookupTable,
                                lu => lu.LookupEntries,
                                lu => lu.LookupEntries.IncludeWithDefaultProperties(
                                    entry => entry.FullValue,
                                    entry => entry.InternalName)
                            )
                        )
                    );

我并不奇怪,当您开始获取任务、自定义字段和查找值时,必须根据查询将其向上移动,这会变得混乱。我建议不要一次获取所有信息,只需在项目级别获取所需信息,然后在任务级别、资源级别、任务级别等。另外,使用Odata从报告数据库中获取信息要快得多。reporting db拥有最新发布的信息,因此它消除了使用草稿数据可能造成的任何混乱。

@sasprog不,我没有。就像我自己回答的其他一些问题一样,我不知道它为什么有效。