1

我们使用将信息存储在 XML 文件中的内部设计工具开发一些产品。为了提供与 TFS 的正确集成,我们还编写了一个提供程序,该提供程序在 TFS 中跟踪用户在使用设计器时的签入和签出操作,而无需与团队资源管理器进行交互。

现在的要求是在签入文件时还添加相关的工作项,我用谷歌搜索并浏览了一些 SDK 示例,但我无法理解是否有一种方法可以显示允许用户关联代码的相同 Windows 窗体代码中的工作项还是我们必须从代码中实现完整的窗口表单(检索和搜索工作项,关联它们,执行签入等等)。任何信息都将不胜感激,因为这两种解决方案在我们需要编写多少代码方面存在很大差异。

4

2 回答 2

1

这是一些帮助更新工作项的代码。此外,请尝试 [此链接][1] 了解更多信息。

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;


namespace WorkItemTrackingSample2
{
    class Program
    {
        static void Main(string[] args)
        {
            // Connect to the server and the store.
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("YourTfsServerNameHere");
            WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
            // Get a specific WorkItem from the store.
            //   Replace "12345" with a WorkItem ID appropriate for testing.
            WorkItem workItem = workItemStore.GetWorkItem(12345);

            // Save the existing Priority so we can restore it later.
            int oldPriority = (int)workItem.Fields["Priority"].Value;

            // Set the Priority to an arbitrarily high number.
            workItem.Fields["Priority"].Value = 9999;

            // Display the results of this change.
            if (workItem.IsDirty)
                Console.WriteLine("The workItem has changed, but has not been saved.");

            if (workItem.IsValid() == false)
                Console.WriteLine("The workItem is not valid.");

            if (workItem.Fields["Priority"].IsValid == false)
                Console.WriteLine("The workItem's Priority field is not valid.");

            // Tries to save the invalid WorkItem.
            try
            {
                workItem.Save();
            }
            catch (ValidationException)
            {
                Console.WriteLine("The workItem threw a ValidationException.");
            }

            // Set the priority to a more reasonable number.
            if (oldPriority == 1)
                workItem.Fields["Priority"].Value = 2;
            else
                workItem.Fields["Priority"].Value = 1;

            // If the WorkItem is valid, saves the changed WorkItem.
            if (workItem.IsValid())
            {
                workItem.Save();
                Console.WriteLine("The workItem saved this time.");
            }

            // Restore the WorkItem's Priority to its original value.
            workItem.Fields["Priority"].Value = oldPriority;
            workItem.Save();
        }
    }
}


  [1]: http://msdn.microsoft.com/en-us/library/bb130323(VS.80).aspx
于 2009-10-26T13:34:57.773 回答
0

我已经与 MS 咨询公司核实过,如果不求助于不安全的低级代码,就无法显示 TFS 或 shell 扩展使用的签入窗口。

So only possible solution is to use the TFS Api to create a new C# control/project to mimic the TFS checkin window.

Regards Massimo

于 2010-06-10T10:03:58.437 回答