我正在尝试解决与TFS API
的合并冲突,并且正在努力解决。我的问题如下:
我无法弄清楚如何做到这一点。请参阅以下代码:
// merge was performed and there are conflicts to resolve
Conflict[] conflicts = ws.QueryConflicts(new string[] {"$/ProjectName/solution/"}, true);
Console.WriteLine(" - Conflicts: {0}", conflicts.Count());
if (conflicts.Any())
{
Console.WriteLine(" - Resolving conflicts");
// There are conflicts to deal with
foreach (Conflict conflict in conflicts)
{
// Attempt to perform merge internally
ws.MergeContent(conflict, false);
if (conflict.ContentMergeSummary.TotalConflicting > 0)
{
// Conflict was not resolved
// Manually resolve
// PROBLEM IS HERE <--------------
var allLines = File.ReadAllLines(conflict.TargetLocalItem).ToList();
allLines.Add("This is the MANUAL merge result");
File.WriteAllLines(conflict.TargetLocalItem, allLines.ToArray());
}
//conflict was resolved
conflict.Resolution = Resolution.AcceptMerge;
ws.ResolveConflict(conflict);
}
}
Checkin(ws, "Merge comment");
Console.WriteLine("Done");
正如您所看到的,我正在尝试手动编辑目标文件,但这不起作用。我似乎无法弄清楚我应该在conflict
对象上编辑哪个文件来手动执行合并。
一位评论者要求我详细说明上述代码的问题:
TargetLocalItem
进行编辑,则不执行任何操作。没有编辑。 基本上我试图模仿外部工具的功能,但我的程序将是外部工具并提供合并文本。
答案 0 :(得分:0)
试试这个
string tmpOutFile = Path.GetTempFileName();
conflict.MergedFileName = tmpOutFile;
// do stuff with tmpOutFile
conflict.Resolution = Resolution.AcceptMerge;
ws.ResolveConflict(conflict);