代码之家  ›  专栏  ›  技术社区  ›  funkymushroom

如何使用NAnt创建可视化源代码安全分支

  •  0
  • funkymushroom  · 技术社区  · 15 年前


    我现在有一个 NAnt vssget 在最新的源代码或特定分支上(使用 ${branch}

    每当我们进行生产构建/部署时,构建的代码树都会创建一个分支,

    问题
    创建分支的过程仍然是手动的,由进入visualsourcesafeexplorer并执行分支过程的人执行。我想知道有没有办法进去 创建VSS分支的步骤。


    我已经知道使用 <exec program="ss">

    有人知道有没有 NAntContrib 目标,或者如果任何人有一个脚本任务,他们在过去曾经这样做,可以提供代码,这将是非常感谢。

    免责声明
    我了解cvs、svn、git和所有其他源代码管理解决方案,目前还不能选择更改工具

    2 回复  |  直到 15 年前
        1
  •  1
  •   Mish Ochu    15 年前

    我工作的地方需要这个。我临时拼凑了一个名为“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>
    

    输出:

    版权所有(C)2001-2006 Gerry Shaw http://nant.sourceforge.net

    构建文件:file:///C:/scm/custom/src/VssBranch/bin/Debug/测试生成 目标框架:Microsoft.NET framework 2.0 指定的目标:运行

    [loadtasks]扫描程序集“分配任务“用于扩展。 [loadtasks]正在扫描程序集“VssBranch”以查找扩展。 [echo]即将执行:VSS分支

    [vssbranch]分支SecurityProto路径:$/VSS/Endur的Source/C#/DailyLive/proto/test branch/SecurityProto

    ....

    生成成功

    总时间:12.9秒。

    显然输出会有所不同,我从一个名为'参数.txt'. 此任务执行VSS世界中所称的“共享和分支”(共享后立即分支)…其他源代码管理系统不需要在分支前共享,呃…那就改天吧

        2
  •  1
  •   Peter Lillevold Rene    15 年前

    vss任务位于NAntContrib项目中,没有,当前没有支持分支的任务。不过,遵循NAntContrib中现有vss任务(添加、签出、签入等)的模型,您可以 grab the source 你自己扩展一下。也就是说, 如果 vssapi支持分支。