2012-04-06 59 views
1

有反正擺脫IBuildDefinition或其他相關的「服務」集合URI。TFS自定義生成模板 - 獲取團隊項目集合不開放的

我想避免必須將uri作爲自定義參數提供給構建模板中的集合。我正在尋找一種方法來從UITypeEditor自定義類中(在此例中)以編程方式檢索它。

有沒有辦法查詢這個,而不訴諸硬編碼?在我看來,構建過程本身(定義,控制器,代理等)知道他們正在處理哪個集合,但我怎麼能找到?

更新:這是從UITypeEditor繼承時的示例代碼。然後你只需訪問VersionControlService的TeamProjectCollection屬性:

public class Editor : UITypeEditor 
    { 
     public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) 
     {   
      if (provider != null) 
      { 
       IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); 

       if (service != null) 
       {      
        VersionControlServer vcs = provider.GetService(typeof(VersionControlServer)) as VersionControlServer; 

// Do what you need to do with it here 

       }  

      return value; 
     } 

     public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) 
     { 
      return UITypeEditorEditStyle.Modal; 
     } 

回答

1

裏面的倍率爲UITypeEditor.EditValue的代碼中的相關行來獲得TeamProjectCollection的是

VersionControlServer vcs = provider.GetService(typeof(VersionControlServer)) as VersionControlServer; 

,然後將其在屬性

vcs.TeamProjectCollection 
+0

返回'null'我:( – Gene 2013-01-24 09:35:05

+0

我發佈的代碼的樣本得到它在更新以上 – 2013-01-24 14:56:29

+0

非常感謝你的努力。看來,如果您引用TFS 2010組件這不起作用和編輯在VS 2012的構建定義(我們使用TFS 2010服務器)。在VS 2010中它像一個魅力。 – Gene 2013-01-24 15:08:13

1

您可以從IBuildServer得到TfsTeamProjectProjection對象:

http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuildserver.teamprojectcollection.aspx

然後讓你的Uri從此對象。

+0

讓我試試吧!我想這可能是我正在尋找的! – 2012-04-06 16:46:29

+0

是否有特殊的方法來檢索實例?我正在使用:IBuildServer buildServer =(IBuildServer)provider.GetService(typeof(IBuildServer));但它回來了。 – 2012-04-06 17:40:42

+0

我爲我的問題添加了一個編輯,以便您可以看到我最終做了什麼。感謝您的輸入。 – 2012-04-06 18:00:30