在我工作的地方,我们实际上需要这个。我拼凑了一个名为“vssbranch”的小任务(不是特别有创意,但这里是代码......一个示例构建文件及其执行的输出:
代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SourceSafeTypeLib;
using NAnt.Core;
using NAnt.Core.Attributes;
namespace NAnt.Contrib.Tasks.SourceSafe
{
[TaskName("vssbranch")]
public sealed class BranchTask : BaseTask
{
/// <summary>
/// The label comment.
/// </summary>
[TaskAttribute("comment")]
public String Comment { get; set; }
/// <summary>
/// Determines whether to perform the branch recursively.
/// The default is <see langword="true"/>
/// </summary>
[TaskAttribute("recursive"),
BooleanValidator()]
public Boolean Recursive { get; set; }
[TaskAttribute("branchname", Required = true)]
public String BranchName { get; set; }
protected override void ExecuteTask()
{
this.Open();
try
{
if (VSSItemType.VSSITEM_PROJECT != (VSSItemType)this.Item.Type)
throw new BuildException("Only vss projects can be branched", this.Location);
IVSSItem newShare = null;
this.Comment = String.IsNullOrEmpty(this.Comment) ? String.Empty : this.Comment;
if (null != this.Item.Parent)
newShare = this.Item.Parent.NewSubproject(this.BranchName, this.Comment);
if (null != newShare)
{
newShare.Share(this.Item as VSSItem, this.Comment,
(this.Recursive) ?
(int)VSSFlags.VSSFLAG_RECURSYES : 0);
foreach (IVSSItem item in newShare.get_Items(false))
this.BranchItem(item, this.Recursive);
}
}
catch (Exception ex)
{
throw new BuildException(String.Format("Failed to branch '{0}' to '{1}'", this.Item.Name, this.BranchName), this.Location, ex);
}
}
private void BranchItem(IVSSItem itemToBranch, Boolean recursive)
{
if (null == itemToBranch) return;
if (this.Verbose)
this.Log(Level.Info, String.Format("Branching {0} path: {1}", itemToBranch.Name, itemToBranch.Spec));
if (VSSItemType.VSSITEM_FILE == (VSSItemType)itemToBranch.Type)
itemToBranch.Branch(this.Comment, 0);
else if (recursive)
{
foreach (IVSSItem item in itemToBranch.get_Items(false))
this.BranchItem(item, recursive);
}
}
}
}
构建文件:
<echo message="About to execute: VSS Branch" />
<echo message="Source Safe Path: ${SourceSafeRootPath}/${CURRENT_FILE}" />
<vssbranch
username="my_user_name"
password="my_password"
recursive="true"
comment="attempt to make a branch"
branchname="test-branch"
dbpath="${SourceSafeDBPath}"
path="${SourceSafeRootPath}/${CURRENT_FILE}"
verbose="true"
/>
</foreach>
</target>
输出:
NAnt 0.85(内部版本 0.85.2478.0;发布;2006 年 10 月 14 日)版权所有 (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net
构建文件:file:///C:/scm/custom/src/VssBranch/bin/Debug/test.build 目标框架:Microsoft .NET Framework 2.0 指定目标:运行
跑:
[loadtasks] 扫描程序集“NAnt.Contrib.Tasks”以获取扩展。[loadtasks] 扫描程序集“VssBranch”以获取扩展。[echo] 即将执行:VSS 分支
……
[vssbranch] 分支 SecurityProto 路径:$/VSS/Endur's Source/C#/DailyLive/proto/test-branch/SecurityProto
……
构建成功
总时间:12.9 秒。
显然输出会有所不同,我将项目从名为“params.txt”的文本文件中拉入分支。此任务执行 VSS 世界中所谓的“共享和分支”(共享后立即分支)......其他源代码控制系统不需要在分支之前共享,嗯......那是另一天