概括
我目前有一个 NAnt 构建执行的脚本 vssget 在最新的源代码或特定分支上(使用 ${branch} 范围)。

每当我们进行生产构建/部署时,构建的代码树都会创建一个分支, (以便我们可以继续开发,并且仍然知道什么代码库正在生产中,相当标准的东西...)

问题
该分支的创建过程仍然是一个手动的过程,该过程由进入Visual Source Safe Explorer并执行分支过程的人执行。我想知道是否有任何办法 NAnt 创建VSS分支。

当前计划
我已经知道使用 <exec program="ss"> 并试图避免这种情况,但是在没有任何更好的解决方案的情况下,这是我将要采取的最可能的路线。

有人知道是否有 NAnt 或者 NAntContrib 为此,或者,如果有人执行了过去的脚本任务,并且可以为此提供代码,那将是非常感谢的。

免责声明
我知道CVS,SVN,GIT和所有其他源控制解决方案,并且要更改工具是当前的选择

有帮助吗?

解决方案

实际上,我们需要我工作的地方。我一起搅动了一个名为“ vssranch”的小任务(不是特别有创意,但这是代码...示例构建文件及其执行的输出:

代码:

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 Shawhttp://nant.sourceforge.net

buildfile:file:/// c:/scm/custom/src/vssbranch/bin/debug/test.build目标框架:Microsoft .NET .NET框架2.0指定目标:运行:运行:运行

跑:

LOADTASKS]扫描组件“ Nant.contrib.tasks”进行扩展。 [loadTasks]扫描组件“ vssranch”用于扩展。 [ECHO]即将执行:VSS分支

....

vssranch] Branching SecurityProto路径:$/vss/endur的源/c#/dailylive/dailylive/proto/test-branch/securityproto

....

构建成功

总时间:12.9秒。

显然,输出会有所不同,我正在从名为“ params.txt”的文本文件中提取项目。此任务执行VSS世界中所谓的“共享和分支”(共享后立即分支)...其他源控制系统在分支之前不需要共享,嗯...那是另一天

其他提示

VSS任务生活在NantContrib项目中,没有,目前没有任何支持分支的任务。但是,按照NantContrib中的现有VSS任务(添加,结帐,检查等)的模型,您可以 抓住来源 并自己扩展。那是, 如果 VSS API支持分支。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top