Get TFS Connection in Custom Build Workflow Parameter Editor

谁说我不能喝 提交于 2019-12-11 20:44:52

问题


So, I am trying to display all available TFS test suites in a custom build workflow parameter editor. See my previous question.

Now I can establish a connection to my TFS instance by using the .Net TFS API just as a normal client Application would. But I would have to embedd the URL to my TFS in the custom assembly, and that's something I would like to avoid.

That got me thinking: This code runs within Visual Studio, so it must somehow be possible to obtain information about the current TFS connection. After searching the web, a lot of different sites showed code about how to do this in a normal Visual Studio extension. So I put together something like this:

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        if (provider != null)
        {
            EnvDTE80.DTE2 dte;
            dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");
            MessageBox.Show("Got dte: " + dte.ActiveDocument.ToString());

            TeamFoundationServerExt ext = dte.DTE.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
            MessageBox.Show("Got tfs: " + ext);

I am able to get the DTE object, calling its ToString() method gives me System.__ComObject, so this part appearantly works. But when I try to get the TeamFoundationServerExt object, I always get null

Any tips why this does not work?


回答1:


So, as it turns out, you do not have to use the DTE stuff at all.

You actually can get the TFS connection like this:

var builddef = (IBuildDefinition)provider.GetService(typeof(IBuildDefinition));
var tpc = builddef.BuildServer.TeamProjectCollection;
var tp = builddef.TeamProject;


来源:https://stackoverflow.com/questions/31198736/get-tfs-connection-in-custom-build-workflow-parameter-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!