Created
August 27, 2012 09:32
-
-
Save kiyokura/3486940 to your computer and use it in GitHub Desktop.
TFSでチェックアウトされているか確認するカスタムタスク
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.Build.Utilities; | |
using Microsoft.Build.Framework; | |
using Microsoft.TeamFoundation.Client; | |
using Microsoft.TeamFoundation.VersionControl.Client; | |
namespace Build.Utils | |
{ | |
public class CheckedInDoneTask : Task | |
{ | |
/// <summary> | |
/// TFSの該当のチームプロジェクトコレクションのパス | |
/// </summary> | |
[Required] | |
public string TfsCollectionUrl { get; set; } | |
/// <summary> | |
/// TFSの該当のチームプロジェクトコレクションのパス | |
/// </summary> | |
[Required] | |
public string TfsTargetSourceFolder { get; set; } | |
public override bool Execute() | |
{ | |
Log.LogMessage("========================================"); | |
Log.LogMessage("チェックアウト状態の確認"); | |
Log.LogMessage("========================================"); | |
Log.LogMessage(string.Format("TfsCollectionUrl:{0}", TfsCollectionUrl)); | |
Log.LogMessage(string.Format("TfsTargetSourceFolder:{0}", TfsTargetSourceFolder)); | |
var tfsCollectionAddress = TfsCollectionUrl; | |
var tfs = new TfsTeamProjectCollection(new Uri(tfsCollectionAddress), | |
new UICredentialsProvider()); | |
tfs.EnsureAuthenticated(); | |
var versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); | |
var itemSpecs = new ItemSpec[1]; | |
itemSpecs[0] = new ItemSpec(TfsTargetSourceFolder, RecursionType.Full); | |
var pendingSets = versionControl.QueryPendingSets(itemSpecs, "", ""); | |
var existPendingSets = false; | |
foreach (var ps in pendingSets) | |
{ | |
foreach (var pc in ps.PendingChanges) | |
{ | |
existPendingSets = true; | |
} | |
} | |
if (existPendingSets) | |
{ | |
Log.LogError("========================================"); | |
Log.LogError("チェックアウト状態の確認でエラー"); | |
Log.LogError(string.Format("ソース管理[{0}]配下に、チェックアウト中のファイルがあります。確認してください", TfsTargetSourceFolder)); | |
Log.LogError("========================================"); | |
return false; | |
} | |
else | |
{ | |
Log.LogMessage("========================================"); | |
Log.LogMessage("チェックアウト中のファイルは無し"); | |
Log.LogMessage("チェックアウト状態の確認-[完了]"); | |
Log.LogMessage("========================================"); | |
return true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment