无法初始化 TFS 存储
Unable to initialize a TFS store
我正在尝试在 Visual Studio Team Services(之前是 Visual Studio Online)中创建任务/工作项。我的代码失败,因为 "tfsStore" returns 空值导致抛出异常。
NetworkCredential myNetCredentials = new NetworkCredential("*****", "******");
ICredentials myCredentials = (ICredentials)myNetCredentials;
Uri tfsUri = new Uri("https://*****.visualstudio.com/DefaultCollection/");
var tfsServer = new TfsTeamProjectCollection(tfsUri, myCredentials);
tfsServer.EnsureAuthenticated();
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(tfsUri);
WorkItemStore tfsStore = tfsServer.GetService<WorkItemStore>();
if (tfsStore == null)
{
throw new Exception("Cannot initialize TFS Store");
}
Project teamProject = tfsStore.Projects["******"];
如果有任何关于如何解决错误的有用提示,我将不胜感激。
谢谢!
我这边测试了下面的代码片段,可以成功创建一个Task工作项,你可以试试:
NetworkCredential myNetCredentials = new NetworkCredential("******", "******");
TfsTeamProjectCollection tfsUri = new TfsTeamProjectCollection(new Uri("https://*****.visualstudio.com/DefaultCollection"), myNetCredentials);
WorkItemStore tfsStore = tfsUri.GetService<WorkItemStore>();
if (tfsStore == null)
{
throw new Exception("Cannot initialize TFS Store");
}
Project teamProject = tfsStore.Projects["*****"];
WorkItemType workItemType = teamProject.WorkItemTypes["Task"];
WorkItem Task = new WorkItem(workItemType)
{
Title = "APITask",
};
Task.Save();
包括.netapi,也可以使用REST API,简单来说就是:
PATCH https://{instance}/DefaultCollection/{project}/_apis/wit/workitems/${workItemTypeName}?api-version={version}
我正在尝试在 Visual Studio Team Services(之前是 Visual Studio Online)中创建任务/工作项。我的代码失败,因为 "tfsStore" returns 空值导致抛出异常。
NetworkCredential myNetCredentials = new NetworkCredential("*****", "******");
ICredentials myCredentials = (ICredentials)myNetCredentials;
Uri tfsUri = new Uri("https://*****.visualstudio.com/DefaultCollection/");
var tfsServer = new TfsTeamProjectCollection(tfsUri, myCredentials);
tfsServer.EnsureAuthenticated();
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(tfsUri);
WorkItemStore tfsStore = tfsServer.GetService<WorkItemStore>();
if (tfsStore == null)
{
throw new Exception("Cannot initialize TFS Store");
}
Project teamProject = tfsStore.Projects["******"];
如果有任何关于如何解决错误的有用提示,我将不胜感激。 谢谢!
我这边测试了下面的代码片段,可以成功创建一个Task工作项,你可以试试:
NetworkCredential myNetCredentials = new NetworkCredential("******", "******");
TfsTeamProjectCollection tfsUri = new TfsTeamProjectCollection(new Uri("https://*****.visualstudio.com/DefaultCollection"), myNetCredentials);
WorkItemStore tfsStore = tfsUri.GetService<WorkItemStore>();
if (tfsStore == null)
{
throw new Exception("Cannot initialize TFS Store");
}
Project teamProject = tfsStore.Projects["*****"];
WorkItemType workItemType = teamProject.WorkItemTypes["Task"];
WorkItem Task = new WorkItem(workItemType)
{
Title = "APITask",
};
Task.Save();
包括.netapi,也可以使用REST API,简单来说就是:
PATCH https://{instance}/DefaultCollection/{project}/_apis/wit/workitems/${workItemTypeName}?api-version={version}