2011-02-07 6 views
5

우리는 사용자 지정 빌드 프로세스 (MS 빌드 사용 안 함)가 있으며이 프로세스 중에 "가짜"빌드를 전역 빌드 목록에 추가합니다. 내가 그렇게하고있는 이유는 주어진 작업 항목 (빌드에서 찾은)에 대한 빌드를 선택할 수 있기 때문이다. 우리는 사용자 정의 필드를 포함하고 있습니다.이 필드는 수정 된 작업 항목을 표시하기위한 것입니다. 프로그래밍 방식으로이 필드를 업데이트하는 방법을 파악하는 데 문제가 있습니다. 아이디어는 빌드 프로세스 중에 호출하여 마지막 빌드 이후의 모든 작업 항목을 찾은 다음 해당 작업 항목의 필드를 업데이트하는 작은 응용 프로그램을 갖게 할 것입니다. 어떤 아이디어?프로그래밍 방식으로 사용자 지정 TFS 필드를 업데이트하는 방법

+0

글로벌 빌드 목록 부분에 대해 자세히 설명해 주실 수 있습니까? Windows Workflow Foundation의 사용자 지정 빌드 템플릿을 사용하고 있습니까? 해당 템플릿의 변수 또는 인수에 추가하고 있습니까? – LWoodyiii

+0

죄송합니다. TFS에서 전체 목록을 사용하고 있습니다. 빌드 템플릿을 사용하지 않고 실제 빌드 자체에 Automated Build Studio라는 제품을 사용하고 있습니다. 이 기능을 위해 ABS에서 호출하는 독립 실행 형 응용 프로그램을 작성하려고했습니다. – Nick

답변

13

이런 식으로 뭔가가 당신을 위해 작동합니다 :

public void UpdateTFSValue(string tfsServerUrl, string fieldToUpdate, 
    string valueToUpdateTo, int workItemID) 
{ 
    // Connect to the TFS Server 
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsUri)); 
    // Connect to the store of work items. 
    _store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); 
    // Grab the work item we want to update 
    WorkItem workItem = _store.GetWorkItem(workItemId); 
    // Open it up for editing. (Sometimes PartialOpen() works too and takes less time.) 
    workItem.Open(); 
    // Update the field. 
    workItem.Fields[fieldToUpdate] = valueToUpdateTo; 
    // Save your changes. If there is a constraint on the field and your value does not 
    // meet it then this save will fail. (Throw an exception.) I leave that to you to 
    // deal with as you see fit. 
    workItem.Save();  
} 

이 호출의 예는 다음과 같습니다

UpdateTFSValue("http://tfs2010dev:8080/tfs", "Integration Build", "Build Name", 1234); 

변수 fieldToUpdate 필드가 아닌 refname의 이름이어야합니다 (예 : 통합 빌드 아니요 Microsoft.VSTS.Build.IntegrationBuild

PartialOpen()을 사용하면 쉽게 벗어날 수 있지만 확실치 않습니다.

프로젝트에 Microsoft.TeamFoundation.Client을 추가해야 할 수도 있습니다. (그리고 어쩌면 Microsoft.TeamFoundation.Common)이 TFS 2012 년 변경

+0

고마워, 이건 내가 찾고 있던거야! – Nick

+0

+1이 답변을 한 번도 투표하지 않은 이유가 궁금하십니까? –

+5

만약 그들이 뭔가를 변경했는지, 아니면 모두가 알아 낸 것이지만 당신이해야 할 일은 확실하지 않습니다. workItem.Fields [fieldToUpdate] .TFS 2012의 값. 그렇지 않으면 필드 컬렉션에 대한 읽기 전용 상태가됩니다. –

4

이 basicly 당신이 workItem.Fields [fieldToUpdate] .Value를 추가해야

버전 @Vaccano 쓴 무엇 업데이트되었습니다.

public void UpdateTFSValue(string tfsServerUrl, string fieldToUpdate, 
    string valueToUpdateTo, int workItemID) 
{ 
    // Connect to the TFS Server 
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsUri)); 
    // Connect to the store of work items. 
    _store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); 
    // Grab the work item we want to update 
    WorkItem workItem = _store.GetWorkItem(workItemId); 
    // Open it up for editing. (Sometimes PartialOpen() works too and takes less time.) 
    workItem.Open(); 
    // Update the field. 
    workItem.Fields[fieldToUpdate].Value = valueToUpdateTo; 
    // Save your changes. If there is a constraint on the field and your value does not 
    // meet it then this save will fail. (Throw an exception.) I leave that to you to 
    // deal with as you see fit. 
    workItem.Save();  
} 
관련 문제