【发布时间】:2015-04-30 11:16:00
【问题描述】:
我创建了签入策略from this MSDN article 作为示例(代码只是复制/粘贴)。
这很好用,当我尝试办理登机手续时会出现,但它会显示为警告。所以我可以通过再次按签入来忽略它。如何更改 URL 中列出的代码,使其返回错误而不是警告。我在 PolicyFailure 上看不到任何属性来执行此操作。
基本上我希望它看起来像这个屏幕截图中的错误:
编辑:这是我正在使用的确切代码。现在它从原始来源略微修改,但没有以我不会想到的任何大规模方式进行。很遗憾,我无法发布屏幕截图,但我会尝试描述我所做的一切。
所以我有一个来自下面代码的 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