How to bind a work item as "associate" or "allow" in Visual Studio TFS API (VS2015)?

I developed a project with the code below:

var pc = ParentSection.GetService<IPendingChangesExt>(); var model = pc.GetType().GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var t = model.FieldType; var mm = model.GetValue(pc); var m = t.GetMethod("AddWorkItemById", BindingFlags.NonPublic | BindingFlags.Instance); m.Invoke(mm, new object[] { selectedWorkItemId }); 

This adds the work item by its identifier to the current pending changes.

Now I want to associate work items that choose between "Associate" or "Resolve" (associate and allow), depending on which button the user clicked on the plugin interface, as shown below: enter image description here

If the user clicks Link and Allow, the work item must be linked and marked as allowed during registration.

If the user clicks Link Only, the work item should only be associated with a set of changes, but not allowed.

Any help would be appreciated.

+5
source share
4 answers

Look, I did it, but I KNOW this is wrong:

After you enable the work item using code to the question:

 IPendingChangesExt pendingChangesExt = ParentSection.GetService<IPendingChangesExt>(); var workItemSection = pendingChangesExt.GetType().GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var modelType = workItemSection.FieldType; var model = workItemSection.GetValue(pendingChangesExt); var m = modelType.GetMethod("AddWorkItemById", BindingFlags.NonPublic | BindingFlags.Instance); m.Invoke(model, new object[] { selectedWorkItemId }); 

I added a few new codes (these are different functions, okay?) ... this second call will wait until the work item appears in the "Related work items of pending changes" section and changes its link to Resolve link manually.

 IPendingChangesExt pendingChangesExt = ParentSection.GetService<IPendingChangesExt>(); var model = pendingChangesExt .GetType() .GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var modelType = model.FieldType; var workItemSection = model.GetValue(pendingChangesExt); var selectedWil = workItemSection .GetType() .GetProperty("SelectedWorkItems") .GetValue(workItemSection) as ObservableCollection<WorkItemValueProvider>; var availablWil = workItemSection .GetType() .GetProperty("WorkItemsListProvider") .GetValue(workItemSection) as WorkItemsListProvider; // Waiting for section to be ready to start association while (!availablWil.WorkItems.Where(x => x.Id == selectedWorkItemId).Any()) { await System.Threading.Tasks.Task.Delay(25); } selectedWil.Clear(); selectedWil.Add(availablWil.WorkItems.Where(x => x.Id == selectedWorkItemId).First()); EnvDTE80.DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; dte2.ExecuteCommand("TeamFoundationContextMenus.WorkItemActionLink.TfsContextPendingChangesPageWorkItemActionLinkAssociate"); selectedWil.Clear(); 

Despite the effectiveness of this code, I am still working on a better solution when running the second method. The default value suggested in the comments will not work, because the developer should be able to bind / allow only when the button is selected.

+1
source

This is not a WorkItem property. This is the check-in action for the work item. You can refer to this link for more details. Changing the default verification option for communication in TFS 2012

You may need to use the CheckinWorkItemAction Enumeration. More information from MSDN .

A similar question about TFS is VS Extension: add a work item to pending changes through the API , and check this link: C # Programmatically Check code changes using the TFS API when linking a change set to a work item


Refresh

If you want to change the default state of 'resolve' to 'associate' , you need

  • change the registry key set HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\1x.0\TeamFoundation\SourceControl\Behavior\ResolveAsDefaultCheckinAction to False.

  • Or For VS2015 there is an option "Tools"> "Options"> "Source Control"> Visual Studio Team Foundation> "Allow related work items to check-in."

enter image description here

Note. Both of the above actions only affect your client machine.

Otherwise, for all users, you need to change the definition of the work item template for the types of work items you use (error, task, etc.). Detailed steps that you can refer to this question How to disable the status of the car for the task during the check

+14
source

There is only one type of link between a work item and a set of changes, and link information is stored in the work item. The difference between Associate and Resolve in Visual Studio is that Associate only associates a work item with a change set, and Resolve changes the work item status to Resolved after associating a work item with a change set.

If you are developing your own plugin, you need to write code to achieve these features manually.

The following code shows how to associate a work item with a set of changes:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.VersionControl.Client; using Microsoft.TeamFoundation.WorkItemTracking.Client; namespace APPI { class Program { static void Main(string[] args) { string url = "http://xxx.xxx.xxx.xxx:8080/tfs/DefaultCollection"; TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(url)); WorkItemStore wis = ttpc.GetService<WorkItemStore>(); VersionControlServer vcs = ttpc.GetService<VersionControlServer>(); int wid = 82; int cid = 332; WorkItem wi = wis.GetWorkItem(wid); Changeset cs = vcs.GetChangeset(cid); ExternalLink el = new ExternalLink(wis.RegisteredLinkTypes["Fixed in Changeset"], cs.ArtifactUri.AbsoluteUri); wi.Links.Add(el); wi.Save(); } } } 
+2
source

For VS 2015. "How to:" Link "the default action for work items" Adapted from https://blogs.msdn.microsoft.com/mitrik/2010/12/03/how-to-make-associate-the- default-action-for-work-items /

0
source

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


All Articles