例として、この MSDN の記事からチェックイン ポリシーを作成しました(コードは単にコピーして貼り付けるだけです)。
これは正常に機能し、チェックインを試みると表示されますが、警告として表示されます。そのため、チェックインをもう一度押すだけで無視できます。URL に記載されているコードを変更して、警告ではなくエラーを返すようにするにはどうすればよいですか。これを行うための PolicyFailure のプロパティが表示されません。
基本的に、このスクリーンショットのエラーのように見せたい:
編集:これが私が使用している正確なコードです。現在は元のソースからわずかに変更されていますが、私が考えていなかったような大規模な方法ではありません。残念ながら、スクリーンショットを投稿することはできませんが、私が行ったことすべてを説明しようと思います.
以下のコードから DLL を取得したので、C:\TFS\CheckInComments.dll のフォルダーに追加しました。チェックイン ポリシーの下に、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");
}
}
}