Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do open an existing work item in Visual Studio from an outside process?

I have a console application which creates a Work Item using TFS API. I want the application to start Visual Studio with the created work item open. I tried:

Process.Start("vstfs:///WorkItemTracking/WorkItem/123?url=http://mytfs:8080/tfs/mycollection")

This opens Visual Studio (I have 2013 update3), and opens a work item saying "opening work item 123...", but VS never actually finishes this open. If I close this window, I get an error The given key was not present in the dictionary.

I tried from commandline/devenv, and both got me the same result:

C:\> start vstfs:///WorkItemTracking/WorkItem/123?url=http://mytfs:8080/tfs/mycollection
C:\> "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" /Tfslink vstfs:///WorkItemTracking/WorkItem/123?url=http://mytfs:8080/tfs/mycollection

I tried opening another TFS item - a build - and that worked fine:

C:\> start vstfs:///Build/Build/111?url=http://mytfs:8080/tfs/mycollection

I could Open them in Web UI - but my users are more comfortable with Visual Studio.

So, How do I launch a work item in VS?

like image 341
Jonathan Avatar asked Nov 09 '22 23:11

Jonathan


1 Answers

I found that I was able to use ShellExecute() to launch TFS with the desired work item loaded.

DECLARE INTEGER ShellExecute ;
    IN SHELL32.dll ;
    INTEGER nWinHandle,;
    STRING cOperation,;
    STRING cFileName,;
    STRING cParameters,;
    STRING cDirectory,;
    INTEGER nShowWindow

ShellExecute(0, 'OPEN', "vstfs:///WorkItemTracking/WorkItem/999999?url=http://mytfsserver:8080/tfs/defaultcollection", '', '', 1)

This code sample is from VFP, but the premise should be the same everywhere.

  • Declare the function in Shell32.dll
  • Call the function with the proper parameters

Here is how to launch TFS with a workitem from the command window:

    START vstfs:///WorkItemTracking/WorkItem/999999?url=http://mytfsserver:8080/tfs/defaultcollection

You can create a batch file and pass in the work item number to make it easier.

like image 109
dashrader Avatar answered Nov 14 '22 22:11

dashrader