【问题标题】:Block Check-In on Policy Failure在策略失败时阻止签入
【发布时间】:2015-04-30 11:16:00
【问题描述】:

我创建了签入策略from this MSDN article 作为示例(代码只是复制/粘贴)。

这很好用,当我尝试办理登机手续时会出现,但它会显示为警告。所以我可以通过再次按签入来忽略它。如何更改 URL 中列出的代码,使其返回错误而不是警告。我在 PolicyFailure 上看不到任何属性来执行此操作。

基本上我希望它看起来像这个屏幕截图中的错误:

Image Source

编辑:这是我正在使用的确切代码。现在它从原始来源略微修改,但没有以我不会想到的任何大规模方式进行。很遗憾,我无法发布屏幕截图,但我会尝试描述我所做的一切。

所以我有一个来自下面代码的 DLL,我已将它添加到 C:\TFS\CheckInComments.dll 的文件夹中。我在 Checkin Policies 下添加了一个带有 DLL 路径的注册表项,字符串值名称与我的 DLL 相同(减去 .dll)。在源代码控制下的项目设置中,我添加了此签入策略。

似乎一切正常,如果我尝试办理登机手续,它会显示一条警告,上面写着“请提供一些关于您办理登机手续的 cmets”,这是我所期望的,我想要的是它如果不符合任何政策,则停止签入,但是我仍然希望用户能够在必要时选择覆盖。目前,即使有警告,如果我点击 Check In 按钮,它将成功签入代码。

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 CheckInComments
{
    [Serializable]
    public class CheckInComments : PolicyBase
    {
        public override string Description
       {
            get
            { 
                return "Remind users to add meaningful comments to their checkins";

            }
        }

        public override string InstallationInstructions
        { 
            get { return "To install this policy, read InstallInstructions.txt"; } 
        }

        public override string Type
        {
            get { return "Check for Comments Policy"; }
        }


        public override string TypeDescription
        {
            get
            {
                return "This policy will prompt the user to decide whether or not they should be allowed to check in";
            }
        }

        public override bool Edit(IPolicyEditArgs args)
        {

            return true;
        }


        public override PolicyFailure[] Evaluate()
        {
            string proposedComment = PendingCheckin.PendingChanges.Comment;
            if (String.IsNullOrEmpty(proposedComment))
            {
                PolicyFailure failure = new PolicyFailure("Please provide some comments about your check-in", this);
                failure.Activate();

                return new PolicyFailure[1]
                {
                    failure
                };
            }
            else
            {
                return new PolicyFailure[0];
            }
        }

        public override void Activate(PolicyFailure failure)
        {
            MessageBox.Show("Please provide comments for your check-in.", "How to fix your policy failure");
        }

        public override void DisplayHelp(PolicyFailure failure)
        {
            MessageBox.Show("This policy helps you to remember to add comments to your check-ins", "Prompt Policy Help");
        }
    }
}

【问题讨论】:

  • 你能添加你的代码和你看到的一步一步的截图吗?
  • 我添加了更多信息。如果您需要更多,请告诉我。

标签: visual-studio-2012 tfs-sdk tfvc checkin-policy


【解决方案1】:

签入策略将始终返回警告,如果您的用户有权忽略它们,那么他们可以。

用户始终可以覆盖该政策。您可以查询 TFS 仓库以生成用户违反政策的报告以及他们提供的违规原因。或者在有人忽略这些礼貌警告时设置警报。

没有办法从策略本身强制执行此操作。仅来自服务器端插件as described by Neno in the post you quoted。也可以为 2012 或 2010 创建这样的服务器端插件。 process is explained here

【讨论】:

  • 您好 jessehouwing,我不一定介意用户是否选择覆盖策略,但我希望它最初显示“签入验证失败。策略警告覆盖原因和/或需要入住记录。”如果失败。与添加内置策略“工作项 - 需要关联的工作项”时的方式类似。获得此功能以阻止所有覆盖的唯一方法是什么?
【解决方案2】:

我刚刚通过在我的项目上打开代码分析解决了这个问题 - 右键单击​​您的项目,单击属性,转到代码分析,选择配置下拉菜单并选择“所有配置”,选择“启用代码分析”构建”。

进行构建并确保没有错误/警告。

这将使您摆脱任何需要在构建时进行代码分析的政策。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 2021-04-16
    • 2018-02-26
    • 2019-11-19
    • 2020-09-12
    相关资源
    最近更新 更多