nantを使用して視覚ソースセーフブランチを作成する方法
-
29-09-2019 - |
質問
概要
私は現在持っています NAnt
aを実行するスクリプトを作成します vssget
最新のソースコードまたは特定のブランチのいずれかで( ${branch}
パラメーター)。
制作ビルド/展開を行うたびに、構築されたコードツリーにはブランチが作成されています。 (開発を継続して、コードベースが生産中のものを知ることができるように、かなり標準的なもの...)
問題
そのブランチの作成プロセスは、視覚的なソースSafe Explorerに参加して分岐手順を実行する人によって実行されるマニュアルのプロセスです。私は何らかの方法があるのだろうかと思っていました NAnt
VSSブランチの作成。
現在の計画
私はすでに使用について知っています <exec program="ss">
そして、それを避けようとしていますが、より良い解決策がない場合、それは私が取る最も可能性の高いルートです。
あるかどうかは誰もが知っていますか? NAnt
また NAntContrib
これのターゲット、または誰かが過去にこれを行うために使用していたスクリプトタスクを持っていて、そのためのコードを提供できる場合、それは非常に高く評価されます。
免責事項
私はCVS、SVN、GIT、その他すべてのソース制御ソリューションについて知っています。
解決
実際に私が働いている場所でこれが必要です。私は「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日)Copyright(c)2001-2006 Gerry Shawhttp://nant.sourceforge.net
buildfile:file:/// c:/scm/custom/src/vssbranch/bin/debug/test.buildターゲットフレームワーク:microsoft .netフレームワーク2.0ターゲット指定:実行:実行する
走る:
LoadTasks]エクステンション用のアセンブリ「nant.contrib.tasks」をスキャンします。 [LoadTasks]拡張機能のためのアセンブリ「vssbranch」をスキャンします。 [エコー]実行しようとする:VSSブランチ
....
vssbranch] Branching SecurityProto Path:$/vss/endur's source/c#/dailylive/proto/test-branch/securityproto
....
ビルドが成功しました
合計時間:12.9秒。
明らかに出力は異なり、「params.txt」という名前のテキストファイルからアイテムを分岐するためにアイテムを引っ張っていました。このタスクは、VSSの世界で「共有と分岐」として知られていることを実行します(共有直後に分岐)...他のソース制御システムは分岐前に共有する必要がありません、ええ...
他のヒント
VSSタスクはNantContribプロジェクトに住んでおり、現在、分岐をサポートするタスクはありません。ただし、NantContribの既存のVSSタスク(追加、チェックアウト、チェックインなど)のモデルに従って、 ソースをつかみます 自分で拡張します。あれは、 もしも VSS APIは分岐をサポートします。