如何在项目之间移动 TFS 2010 构建定义?

发布于 2024-10-19 01:01:46 字数 118 浏览 1 评论 0原文

我有一些在 ProjectX 下创建的 TFS 2010 构建定义。现在源代码已移至 ProjectY 下属的文件夹中。如何将构建定义移至 ProjectY,以便它们显示在 ProjectY 的团队资源管理器的构建节点下?

I have some TFS 2010 build definitions that were created under ProjectX. Now the source code has moved to a folder subordinate to ProjectY. How can I move the build definitions to ProjectY so they display under the Builds node of the Team Explorer for ProjectY?

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

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

发布评论

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

评论(6

疧_╮線 2024-10-26 01:01:46

我认为没有现成的东西可以将构建定义从一个项目复制到另一个项目。不过,您应该能够使用 TFS API 来完成此操作。您将需要将构建过程模板(这就是 Pete 所指的)移动到新项目的构建过程模板文件夹中。之后,您将执行以下操作:

var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<server uri>"));

IBuildServer buildServer = server.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuildDefinitions("Project X");
foreach(var build in buildDetails)
{
        var buildDefinition = buildServer.CreateBuildDefinition("Project Y");
        buildDefinition.Name = "Copy of " + build.Name;
        buildDefinition.BuildController = build.BuildController;
        // This finds the template to use
        buildDefinition.Process = buildServer.QueryProcessTemplates("Project Y")[0]; 
        buildDefinition.ProcessParameters = build.ProcessParameters;
        buildDefinition.Save();                
}

有几件事需要注意。您将需要处理将工作区映射从一个项目转换为另一项目的情况。您还需要更改 buildDefinition.Process 行以查找特定模板。

I don't think there is something out of the box to copy the build definitions from one project to another. However you should be able to do it using the TFS API. You will want to move the build process templates, which is what Pete is referring to, into the Build Process Template folder for the new project. After that you would do something like:

var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<server uri>"));

IBuildServer buildServer = server.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuildDefinitions("Project X");
foreach(var build in buildDetails)
{
        var buildDefinition = buildServer.CreateBuildDefinition("Project Y");
        buildDefinition.Name = "Copy of " + build.Name;
        buildDefinition.BuildController = build.BuildController;
        // This finds the template to use
        buildDefinition.Process = buildServer.QueryProcessTemplates("Project Y")[0]; 
        buildDefinition.ProcessParameters = build.ProcessParameters;
        buildDefinition.Save();                
}

A couple of things to note. You will need deal with converting the workspace mappings from one project to the other. You will also need to change the buildDefinition.Process line to find the specific template.

冰葑 2024-10-26 01:01:46

Sean 上面的答案的 powershell 版本

# Copy some TFS build defintions from one project collection to another

[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")

$tfsUrl = "http://lontfs_at:8080/tfs/XXX"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsUrl)
$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$buildServer = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

$buildDetails = $buildServer.QueryBuildDefinitions("Project X");
foreach( $build in $buildDetails)
{
        $buildDefinition = $buildServer.CreateBuildDefinition("Project Y");
        $buildDefinition.Name = "Copy of " + $build.Name;
        $buildDefinition.BuildController = $build.BuildController;
        # This finds the template to use
        $buildDefinition.Process = $buildServer.QueryProcessTemplates("Project Y")[0]; 
        $buildDefinition.ProcessParameters = $build.ProcessParameters;
        $buildDefinition.Save();                
}

A powershell version of Sean's answer above

# Copy some TFS build defintions from one project collection to another

[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")

$tfsUrl = "http://lontfs_at:8080/tfs/XXX"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsUrl)
$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$buildServer = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

$buildDetails = $buildServer.QueryBuildDefinitions("Project X");
foreach( $build in $buildDetails)
{
        $buildDefinition = $buildServer.CreateBuildDefinition("Project Y");
        $buildDefinition.Name = "Copy of " + $build.Name;
        $buildDefinition.BuildController = $build.BuildController;
        # This finds the template to use
        $buildDefinition.Process = $buildServer.QueryProcessTemplates("Project Y")[0]; 
        $buildDefinition.ProcessParameters = $build.ProcessParameters;
        $buildDefinition.Save();                
}
§对你不离不弃 2024-10-26 01:01:46

在 VS2010 中,TFS Power Tools 可以将构建定义从一个项目移动到另一个项目,如以下链接中的第二个答案所示:是否可以导出 TFS 2010 构建定义?,如下所示。

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tfpt 
builddefinition /collection:"http://ServerX:8080/tfs/Collection X" /clone "Project 1\Build 
Definition X" "Project 2\Copy of Build Definition X"

可以从以下位置下载适用于 VS2010 的 TFS Power Tools:http://visualstudiogallery .msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f

In VS2010, the TFS Power Tools can move a build definition from one project to another as demonstrated in the 2nd answer in this link: Is it possible to Export TFS 2010 Build Definitions?, and as shown below.

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tfpt 
builddefinition /collection:"http://ServerX:8080/tfs/Collection X" /clone "Project 1\Build 
Definition X" "Project 2\Copy of Build Definition X"

The TFS Power Tools for VS2010 can be downloaded from: http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f

允世 2024-10-26 01:01:46

丑陋但非常有效的方法移动(不重复)仅一两个构建定义:

  • 打开 SQL Server Management Studio,
  • 打开集合数据库
  • 编辑表 tbl_BuildDefinition
  • 将当前 GroupId 替换为目标团队项目的 GroupId

就是这样;)

要确定目标团队项目的 GroupId,只需在 tbl_BuildDefinition 中找到该团队项目的任何 BuildDefinition 并获取其 GroupId 即可。

当然,您接下来必须更新 BuildDefinition 的工作区、要构建的项目……以使用新团队项目的服务器路径!

如果您在更新 BuildDefinition 时收到类似“GroupItem 无法跨团队项目移动”的错误,则它很可能在更新数据库之前已打开。关闭并重新打开它。

如果您不想经常重复此操作,那么在我看来,这是最快的解决方案。

五、

Uggly but very efficient way to move (not to duplicate) only one or two Build Definitions:

  • Open SQL Server Management Studio,
  • Open your Collection DB
  • Edit the table tbl_BuildDefinition
  • Replace the current GroupId with the target Team Project's GroupId

That's it ;)

To determine the GroupId of the target Team Project, simply find any BuildDefinition of that Team Project in tbl_BuildDefinition and take its GroupId.

For sure, you have next to update the BuildDefinition's workspace, Items to build, ... to use the server path of the new Team Project !

If you get an error like "GroupItem cannot be move accross Team Project" when updating your BuildDefinition, it was most probably already open before updating the DB. Close and reopen it.

If you don't intend to repeat this operation too often, it's IMO the fastest solution.

V.

情绪 2024-10-26 01:01:46

构建定义只是 TFS 中的另一个源代码控制文件,您应该能够在 ProjectX 中打开构建定义并将其作为新文件保存到 projectY 的构建定义文件夹中。

编辑
在上面的文章中,我假设 ProjectX 和 ProjectY 是 TFS 项目,在这种情况下,它们的工作流构建定义仅位于其各自源代码控制根目录的 builddfinitions 文件夹中。

Build definitions are just another source controled file in TFS, you should be able to open the build definition in ProjectX and save it as a new file to projectY's build definitions folder.

Edit
In the above post I am assuming ProjectX and ProjectY are TFS projects, in which case their workflow build definition(s) are simply in the builddfinitions folder of their respective source control roots.

尸血腥色 2024-10-26 01:01:46

Sean 的回答帮助了我,但就我而言,我只有一个用于构建模板和自定义活动程序集的存储库。所以我不需要编辑设置,我只想将一个构建定义从 TFS 项目 A 复制到 TFS 项目 B。
这是我的 Sean 代码的“简短”版本:

var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS URL"));
IBuildServer buildServer = server.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuildDefinitions("Proj_A");
foreach(var build in buildDetails)
{
    var buildDefinition = buildServer.CreateBuildDefinition("Proj_B");
    buildDefinition.CopyFrom(build);
    buildDefinition.Save();
}

Sean's answer helped me out, but in my case, I have only one repository for my build templates and custom activities assemblies. So I don't need to edit settings, I just want to copy one build definition from TFS Project A to TFS Project B.
Here is my 'short' version of Sean's code:

var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS URL"));
IBuildServer buildServer = server.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuildDefinitions("Proj_A");
foreach(var build in buildDetails)
{
    var buildDefinition = buildServer.CreateBuildDefinition("Proj_B");
    buildDefinition.CopyFrom(build);
    buildDefinition.Save();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文