How to open an existing work item in Visual Studio from an external process?

I have a console application that creates a work item using the TFS API. I want the application to start Visual Studio with an open work item. I tried:

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

This opens Visual Studio (I have an update of 20133) and opens a work item that says "Opening work item 123 ...", but VS never ends this opening. If I close this window, I get the error message The given key was not present in the dictionary .

I tried / devenv from the command line and both gave 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 to open another TFS element - assembly - and it worked fine:

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

I could open them in the web interface - but my users are more convenient with Visual Studio.

So, how to run a work item in VS?

+5
source share
1 answer

I found that I was able to use ShellExecute () to start TFS with the required 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 sample code is from VFP, but the premise should be the same everywhere.

  • Declare a function in Shell32.dll
  • Call a function with the appropriate parameters

Here's how to start TFS with a work item from the command line:

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

You can create a batch file and pass the work item number to simplify it.

+1
source

Source: https://habr.com/ru/post/1205775/


All Articles