简体   繁体   中英

Get TFS Connection in Custom Build Workflow Parameter Editor

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM