Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2012 策略失败时阻止签入_Visual Studio 2012_Tfs Sdk_Tfvc_Checkin Policy - Fatal编程技术网

Visual studio 2012 策略失败时阻止签入

Visual studio 2012 策略失败时阻止签入,visual-studio-2012,tfs-sdk,tfvc,checkin-policy,Visual Studio 2012,Tfs Sdk,Tfvc,Checkin Policy,我创建了签入策略作为示例(代码只是复制/粘贴的) 这很好,当我尝试签入时它会出现,但是它会显示为警告。所以我可以通过再次按Check In忽略它。如何更改URL中列出的代码,使其返回错误而不是警告。我在Policy上看不到任何属性。未能执行此操作 基本上,我希望它看起来像这个屏幕截图中的错误: 编辑:以下是我使用的确切代码。现在它是从原始源代码稍微修改的,但不是以任何我想不到的大规模方式。不幸的是,我不能发布截图,但我会尝试描述我所做的一切 因此,我从下面的代码中获得了一个DLL,我已将其添

我创建了签入策略作为示例(代码只是复制/粘贴的)

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

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

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

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

这一切似乎都很好,如果我尝试签入,它将显示一个警告,说“请提供一些关于您的签入的评论”,这是我所期望的,我希望它停止签入,如果任何政策没有得到满足,但是我仍然希望用户能够选择覆盖,如果必要的话。目前,即使有一个警告,如果我点击checkin按钮,它也会成功地签入代码

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");
        }
    }
}

签入策略将始终返回警告,如果您的用户具有忽略警告的权限,则他们可以忽略警告

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


没有办法从政策本身强制执行这一点。仅来自服务器端插件。这样的服务器端插件也可以在2012年或2010年创建。.

我刚刚通过对我的项目启用代码分析解决了这个问题-右键单击您的项目,单击属性,转到代码分析,选择配置下拉列表并选择“所有配置”,选择“在生成时启用代码分析”

执行生成并确保没有错误/警告


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

Hi jessehouwing,我不一定介意用户是否选择覆盖策略,但我希望它最初显示“签入验证失败。需要策略警告覆盖原因和/或签入说明”。如果失败。与添加内置策略“Work Items-Require associated Work Items”(工作项-需要关联的工作项)时的情况类似。获得此功能以阻止所有覆盖的唯一方法是什么?要使错误显示在顶部,您需要服务器端插件,但点击两次签入不应绕过该策略,这看起来像是实现中的一个bug。你能一步一步地添加代码和屏幕截图吗?我已经添加了更多信息。如果您需要更多,请告诉我。