TFS客户端侧挂钩

时间:2014-09-12 06:21:43

标签: visual-studio tfs checkin-policy tfvc

我们使用TFS作为版本控制。目前,项目管理是通过我们当地的PMS应用程序完成的。我们有一个要求,例如当团队成员检查项目时,显示用于输入任务详细信息的自定义对话框并更新我们的本地pms数据库。我想显示一个自定义对话框,和/或在调用签入命令之后。同时确保只通过此自定义对话框成功提交任务详细信息,我们可以签入项目。

2 个答案:

答案 0 :(得分:9)

创建自己的签到政策

您可以通过签到政策执行此操作。 Check out my blog post on interacting with the user on check-in。基本技巧是提出用户可以单击的签入警告,在单击事件上,您可以向用户显示UI并使用标准Windows窗体功能与您的系统进行交互。

最多basic example code can be found in this StackOverflow question

My multiple Branch policy uses this trick要求用户确认用户是否确实要同时将代码签入多个分支,而不必使用绕过策略验证复选框。


关于安装Checkin政策的说明

配置Team项目以使用签入策略后,Visual Studio会在签入时未在计算机上安装策略时进行投诉。没有简单的方法来分发签入策略,以确保每个用户都在其计算机上安装它,或者自动从TFS安装它。

在您的签到政策中,您可以通过IPolicyDefinition.InstallationInstructions为政策包的位置提供URI。该软件包可以是.msi.vsix或只是一个zip文件,其中包含用于复制程序集和添加所需注册表项的脚本。 Visual Studio不关心您选择的方法。如果您的公司hosts their own Visual Studio gallery,它也可以指向那里的下载位置。

如果您选择.msi,则可以通过组织中可用的现有配置工具进行分发。

未安装策略的客户端将自动触发签入时的警告,该警告只能通过选中“绕过签入策略”复选框来解除。该权限可以被撤销,要求所有用户正确设置他们的机器。

还有一种方法可以分发签入政策which is through the Visual Studio Power tools。通过签入特定文件夹中的源代码管理中的策略并告诉Power Tools下载自定义二进制文件(工作项控件和签入策略),它们将自动安装。由于这些工具默认情况下未安装,默认情况下未配置,因此需要大量相同的工作才能使此方案适合您。

答案 1 :(得分:4)

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.TeamFoundation.VersionControl.Client;
    namespace TFSPMSIntegration
    {
        [Serializable]
        public class CheckForPMSDetails : PolicyBase
        {
            public bool pmsDetailsConfirmed=false;
            private static frmPmsDetails _frm = null;
            public override string Description
            {
                get { return "Remind users to add PMS details to their checkins"; }
            }

            // This is a string that is stored with the policy definition on the source
            // control server.  If a user does not have our policy plugin installed, this string
            // will be displayed.  We can use this as an opportunity to explain to the user
            // how they might go about installing our policy plugin.
            public override string InstallationInstructions
            {
                get { return "To install this policy, follow the instructions in CheckForPMSDetails.cs."; }
            }

            // This string is the type of our policy.  It will be displayed to the user in a list
            // of all installed policy types when they are creating a new policy.
            public override string Type
            {
                get { return "Check for PMS Details"; }
            }

            // This string is a description of the type of our policy.  It will be displayed to the
            // user when they select our policy type in the list of policies installed on the system
            // as mentioned above.
            public override string TypeDescription
            {
                get { return "This policy will prompt the user to decide whether or not they should be allowed to check in."; }
            }

            // This method is invoked by the policy framework when the user creates a new checkin
            // policy or edits an existing checkin policy.  We can use this as an opportunity to
            // display UI specific to this policy type allowing the user to change the parameters
            // of the policy.
            public override bool Edit(IPolicyEditArgs args)
            {
                // no configuration to save
                return true;
            }

            // This method performs the actual evaluation.  It is called by the policy framework at various points in time
            // when policy should be evaluated.  In this example, we invoke this method ourselves when various asyc
            // events occur that may have invalidated the current list of failures.
            public override PolicyFailure[] Evaluate()
            {


                if (!pmsDetailsConfirmed)
                {
                    return new PolicyFailure[] {
                        new PolicyFailure("Please provide PMS Details about your checkin", this),
                    };
                }
                else
                {
                   //frmPmsDetails frm = Application.OpenForms["frmPmsDetails"] as frmPmsDetails;
                    if(_frm!=null)
                    PendingCheckin.PendingChanges.Comment = _frm.txtDescription.Text;
                    return new PolicyFailure[0];
                }
            }

            // This method is called if the user double-clicks on a policy failure in the UI.
            // We can handle this as we please, potentially prompting the user to perform
            // some activity that would eliminate the policy failure.
            public override void Activate(PolicyFailure failure)
            {
                //The Singleton design pattern is used for maitntain only one instance of Form class(UI).But everytime we have passing new value to the custom policy class.
                //Singleton approach needed , otherwise each time we click on policy message error, it will open multiple forms(UI)
                if (_frm == null)
                    _frm = new frmPmsDetails(this);
                else
                    _frm.CheckForPMSDetails = this;

                _frm.WindowState = FormWindowState.Minimized;
                _frm.TopMost = true;
                _frm.Show();
               _frm.ClearAll();
                _frm.WindowState = FormWindowState.Normal;
                _frm.BringToFront();

            }
            public void fn_Evaluate()
            {

                pmsDetailsConfirmed = true;
                base.OnPolicyStateChanged(Evaluate());


            }

            // This method is called if the user presses F1 when a policy failure is active in the UI.
            // We can handle this as we please, displaying help in whatever format is appropriate.
            // For this example, we'll just pop up a dialog.
            public override void DisplayHelp(PolicyFailure failure)
            {
                MessageBox.Show("This policy helps you to remember to add PMS details to your checkins.", "Prompt Policy Help");
            }

        }
    }

自定义签入政策部署

  • 首先使用您的自定义签入策略创建类库 业务逻辑

  • 使用VSIX软件包向客户部署签入策略, 这很容易安装。

  • 您想为VS 2010,VS 2012构建自定义签到策略, 和VS 2013,然后你需要一台机器,包括所有这三个 Visual Studio版本并排安装,您将需要 为每个安装Visual Studio SDK。 VSIX项目 模板仅在成功安装Visual后才可用 Studio SDK。

在Visual Studio 2012版本中使用VSIX包创建签入策略的步骤

1.在visual studio 2012版本中创建新项目。

2.选择Extensibility项目模板,然后选择VSIX Project模板。 enter image description here

  1. 在VSIX项目中添加对自定义签入策略项目的引用 enter image description here
  2. 您应该向项目添加一些项目,例如icon bitmap和License.txt,但只有其中一项是强制性的:“policies.pkgdef” enter image description here

    1. 您只需添加一个文本文件,并将其命名为policies.pkgdef。名称可以是任何名称,但扩展名应为“pkgdef”。
  3. 编辑policies.pkgdef,如下所示:
  4. [$ RootKey $ \ TeamFoundation \ SourceControl \ Checkin Policies] " TFSPMSIntegration" =" $ PackageFolder $ \ TFSPMSIntegration.dll" enter image description here

    第1部分:这是您选择提供策略包的名称,它是注册表中密钥的名称 第2部分:这是在项目属性,应用程序/程序集名称字段中定义的程序集名称。

    1. 最后你必须设置一个名为source.extension.vsixmanifest的vsixmanifest文件。
    2. 选择“资产”标签,然后使用“添加新资源”窗口添加“policies.pkgdef”文件 enter image description here

    3. 您必须构建解决方案,并通过双击安装VSIX。请注意,它在您重新启动Visual Studio时首先生效。

    4. *要禁用和卸载软件包,请转到visual studio tools菜单并选择“Extension and Updates” enter image description here

      选择扩展程序并执行相应的操作 enter image description here

相关问题