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

Version control 如何使用NAnt创建可视化源代码安全分支,version-control,branch,nant,visual-sourcesafe,nantcontrib,Version Control,Branch,Nant,Visual Sourcesafe,Nantcontrib,摘要 我目前有一个NAnt构建脚本,它对最新的源代码或特定的分支(使用${branch}参数)执行vssget <echo message="About to execute: VSS Branch" /> <echo message="Source Safe Path: ${SourceSafeRootPath}/${CURRENT_FILE}" /> <vssbranch usern

摘要
我目前有一个
NAnt
构建脚本,它对最新的源代码或特定的分支(使用
${branch}
参数)执行
vssget

        <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>
无论何时我们进行生产构建/部署,构建的代码树都会创建一个分支(这样我们就可以继续开发,并且仍然知道生产上的代码库是什么,非常标准的东西…)

        <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>
问题
创建该分支的过程仍然是手动的,由进入Visual Source Safe Explorer并执行分支过程的人员执行。我想知道在
NAnt
中是否有创建VSS分支的方法

        <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>
当前计划
我已经知道如何使用
,我正试图避免这种情况,但在没有更好的解决方案的情况下,这是我最可能采取的方法

        <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
NAntContrib
目标,或者是否有人有一个脚本任务,他们过去曾经这样做过,并且可以为此提供代码,这将非常感谢

        <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>
免责声明

我了解cvs、svn、git和所有其他源代码管理解决方案,并且目前无法更改该工具。vss任务位于NAntContrib项目中,目前没有支持分支的任务。不过,遵循NAntContrib中现有vss任务(添加、签出、签入等)的模型,您可以自己对其进行扩展。也就是说,如果VSS API支持分支的话。

在我工作的地方,我们实际上需要它。我临时拼凑了一个名为“vssbranch”的小任务(不是特别有创意,但下面是代码…一个示例构建文件及其执行的输出:

        <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>
代码:
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用系统文本;
使用SourceSafeTypeLib;
使用NAnt.Core;
使用NAnt.Core.Attributes;
命名空间NAnt.Contrib.Tasks.SourceSafe
{
[任务名称(“vssbranch”)]
公共密封类BranchTask:BaseTask
{
/// 
///标签注释。
/// 
[任务属性(“注释”)]
公共字符串注释{get;set;}
/// 
///确定是否以递归方式执行分支。
///默认值是
/// 
[TaskAttribute(“递归”),
BooleanValidator()]
公共布尔递归{get;set;}
[TaskAttribute(“branchname”,必选=true)]
公共字符串BranchName{get;set;}
受保护的覆盖无效ExecuteTask()
{
这个.Open();
尝试
{
if(VSSItemType.VSSITEM_项目!=(VSSItemType)this.Item.Type)
抛出新的BuildException(“只能分支vss项目”,this.Location);
IVSSItem newShare=null;
this.Comment=String.IsNullOrEmpty(this.Comment)?String.Empty:this.Comment;
if(null!=此.Item.Parent)
newShare=this.Item.Parent.NewSubproject(this.BranchName,this.Comment);
如果(空!=新闻共享)
{
newShare.Share(this.Item作为VSSItem,this.Comment,
(这是递归的)?
(int)VSSFlags.VSSFLAG_recurseyes:0);
foreach(新闻共享中的IVSSItem项。获取_项(false))
this.BranchItem(item,this.Recursive);
}
}
捕获(例外情况除外)
{
抛出新的BuildException(String.Format(“未能将“{0}”分支到“{1}”、this.Item.Name、this.BranchName)、this.Location、ex);
}
}
私有void BranchItem(IVSSItem itemToBranch,布尔递归)
{
if(null==itemToBranch)返回;
if(this.Verbose)
Log(Level.Info,String.Format(“分支{0}路径:{1}”,itemToBranch.Name,itemToBranch.Spec));
if(VSSItemType.VSSITEM_文件==(VSSItemType)itemToBranch.Type)
itemToBranch.Branch(this.Comment,0);
else if(递归)
{
foreach(itemToBranch.get_Items中的IVSSItem项(false))
这个.BranchItem(项,递归);
}
}
}
}
生成文件:

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

        <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;发布;10/14/2006) 版权所有(C)2001-2006 Gerry Shaw

        <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>
构建文件:file:///C:/scm/custom/src/VssBranch/bin/Debug/test.build 目标框架:Microsoft.NET framework 2.0 指定的目标:运行

        <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>
运行:

        <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>
[loadtasks]扫描程序集“NAnt.Contrib.Tasks”以获取扩展。 [loadtasks]扫描程序集“VssBranch”以获取扩展。 [echo]即将执行:VSS分支

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

        <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>
[vssbranch]分支SecurityProto路径:$/VSS/Endur的Source/C#/dailyllive/proto/test branch/SecurityProto

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

        <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>
建造成功

        <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>
总时间:12.9秒

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

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

这正是我所怀疑的,但感谢您的确认。我实际上已经下载了NAntContrib源代码并开始摆弄它,但我怀疑我是否能获得足够的“官方”是时候编写我自己的vssbranch任务了,所以我可能会将exec与ss.exe一起使用。我是否必须在单独的DLL中构建此任务,还是应该将其放置在原始NAntContrib解决方案文件中?如果我将其构建到原始NAntContrib解决方案中,是否应该使用bu
        <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>