2016-06-12 2 views
0

Visual Studio Team Services (이전 Visual Studio Online)에서 작업/작업 항목을 만들려고합니다. "tfsStore"가 예외를 발생시키는 null 값을 반환하기 때문에 코드가 실패합니다.TFS 저장소를 초기화 할 수 없습니다.

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["******"]; 

나는 오류를 해결하는 방법에 관한 유용한 팁을 부탁드립니다. 감사합니다.

내가 성공적으로 작업 작업 항목을 만들 수 있습니다 내 옆에 아래의 코드를 테스트 한

답변

0

, 당신은 시도 할 수 있습니다 : 당신은 또한 REST API를 사용하여 .NET API를 포함

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(); 

을하는 단순히 :

PATCH https://{instance}/DefaultCollection/{project}/_apis/wit/workitems/${workItemTypeName}?api-version={version} 
+0

tfsStore가 null이므로 여전히 "TFS 저장소를 초기화 할 수 없습니다."라는 예외가 발생합니다. 고마워! – JayHawk

+0

어 ...이 코드는 내 편이 잘 작동합니다. 이 코드가 VSTS에 성공적으로 연결 되었습니까? –

+0

예. VSTS에 성공적으로 연결할 수 있습니다. 그러나 WorkItemStore를 인스턴스화하지 못했습니다. REST API를 사용하여 코드를 작동시킬 수 있었으므로 문제가되지 않는다고 생각합니다. 감사! – JayHawk

관련 문제