阻止政策失败的签到

问题描述 投票:2回答:2

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

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

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

Image Source

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

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

这一切似乎都很好,如果我尝试办理登机手续,它会显示一条警告,上面写着“请提供一些关于你办理登机手续的评论”这是我所期待的,我希望它能阻止它如果不符合任何政策,我们仍然希望用户能够在必要时选择覆盖。目前,即使有警告,如果我点击“检入”按钮,那么它将成功检入代码。

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 tfs2010 tfs-sdk tfvc checkin-policy
2个回答
1
投票

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

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

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


0
投票

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

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

这将使您通过任何需要在构建时进行代码分析的策略。

© www.soinside.com 2019 - 2024. All rights reserved.