如何使用 NAnt 创建 Visual Source Safe 分支

发布于 2024-09-14 22:48:11 字数 651 浏览 1 评论 0原文

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

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

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

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

有谁知道是否有一个 NAnt 或 NAntContrib 目标,或者是否有人有一个他们过去用来执行此操作的脚本任务并且可以提供代码为此,我们将非常感激。

免责声明
我了解 cvs、svn、git 和所有其他源代码控制解决方案,目前无法更改工具

Summary
I currently have a NAnt build script that performs a vssget on either the latest source code, or a specific branch (using a ${branch} parameter).

Whenever we do a production build/deployment the code-tree that was built has a branch created, (so that we can continue development and still know what codebase is on production, pretty standard stuff...)

Problem
The process of creation of that branch is still a manual one, performed by someone going into Visual Source Safe Explorer and performing the branching procedure. I was wondering if there is any way in NAnt of creating a VSS branch.

Current Plan
I already know about using <exec program="ss"> and am trying to avoid that, but in the absence of any better solutions, that is the most probable route I will take.

Does anyone know if there is a NAnt or NAntContrib target for this, or if anyone has a script task that they have used to do this in the past and could provide the code for that, that would be very much appreciated.

Disclaimer
I know about cvs, svn, git and all the other Source Control solutions, and to change the tool is not an option at present

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痕至 2024-09-21 22:48:11

我工作的地方实际上需要这个。我整理了一个名为“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
指定目标: run

run:

[loadtasks] 扫描程序集“NAnt.Contrib.Tasks”以获取扩展。
[loadtasks] 扫描程序集“VssBranch”以获取扩展。
[echo] 即将执行:VSS Branch

....

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

....

BUILD SUCCEEDED

总时间:12.9 秒。

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

We actually need this where I work. I whipped together a small task called 'vssbranch' (not particularly creative but here is the code...an example build file and the output of its execution:

CODE:

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);
            }
        }
    }
}

BUILD FILE:

        <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>

OUTPUT:

NAnt 0.85 (Build 0.85.2478.0; release; 10/14/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/scm/custom/src/VssBranch/bin/Debug/test.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: run

run:

[loadtasks] Scanning assembly "NAnt.Contrib.Tasks" for extensions.
[loadtasks] Scanning assembly "VssBranch" for extensions.
[echo] About to execute: VSS Branch

....

[vssbranch] Branching SecurityProto path: $/VSS/Endur's Source/C#/DailyLive/proto/test-branch/SecurityProto

....

BUILD SUCCEEDED

Total time: 12.9 seconds.

Obviously the output would vary, I was pulling in the items to branch from a text file named 'params.txt'. This task performs what is known in the VSS world as 'Share and Branch' (Branching immediately after Sharing)...other source control systems do not need to share before branching, eh...that's for another day

猛虎独行 2024-09-21 22:48:11

vss 任务位于 NAntContrib 项目中,目前没有支持分支的任务。不过,按照 NAntContrib 中现有 vss 任务(添加、签出、签入等)的模型,您可以 获取源代码并自行扩展。也就是说,如果VSS API 支持分支。

The vss tasks live in the NAntContrib project and no, currently there is no task that supports branching. Though, following the model of the existing vss tasks (add, checkout, checkin, etc) in NAntContrib, you could grab the source and extend it yourself. That is, if the VSS API supports branching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文