Visual Studio构建任务 - TFS操作

时间:2009-11-20 12:42:24

标签: visual-studio tfs msbuild

我正在寻求扩展一些后期构建任务,以包括签出然后检入DLL。我们正在使用TFS,我知道有命令行工具可以做到这一点。我不知道该怎么做是将这些内容集成到我现有的后期构建任务中。现在我的后期构建任务很简单,并通过项目属性在Visual Studio中进行管理。最终我想将我的自定义构建任务分解为外部文件并调用它们,但这是另一个问题的主题;)

5 个答案:

答案 0 :(得分:4)

无需借助自定义构建任务,您可以尝试使用Team Foundation Source Control Command-Line tool(tf.exe)。

下面的示例显示了如何使用tf.exe从TFS签出文件。

<PropertyGroup>
    <TfCommand>
        &quot;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\tf.exe&quot;
    </TfCommand>
</PropertyGroup>

<Target Name="AfterCompile">
    <Exec Command="$(TfCommand) get /force /noprompt &quot;$(SolutionRoot)\sources\example.cs&quot;"
        ContinueOnError="true" />
    <Exec Command="$(TfCommand) checkout &quot;$(SolutionRoot)\sources\example.cs&quot;"
        ContinueOnError="true"/>
</Target>

将其包含在您自己的MSBuild项目文件中。

此示例没有做任何有用的事情,您需要更改它以匹配您的环境,但也许它可以帮助您开始。

我从tfsbuild.com得到了这个例子。

答案 1 :(得分:0)

您可以使用Team Foundation Server client APITeamFoundationServer是允许您连接到服务器,列出和操作TFS项目的基类。

答案 2 :(得分:0)

Msbuildtasks有一些带有源代码的msbuild扩展(它的开源)。您可以使用它来创建自己的签入/签出功能。 (与达林建议的结合)

http://msbuildtasks.tigris.org/

答案 3 :(得分:0)

查看CodePlex上的SDC Tasks Library。它是一组自定义MSBuild任务,包括Checkin和Checkout任务(请参阅随附文档中的Microsoft.Sdc.Tasks.SourceTfs命名空间)。您可以将这些任务合并到项目文件中的“AfterBuild”目标中。

<SourceTfs.Checkout Path="Path" TfsVersion="tfsVersion"
WorkingDirectory="workingDirectory"/>

<SourceTfs.Checkin Path="Path" Comments="Comments" TfsVersion="tfsVersion" 
WorkingDirectory="workingDirectory" Override="overrideText"/>

您可以根据需要将TfsVersion设置为“2005”或“2008”。

答案 4 :(得分:0)

我们的团队有几个小项目,输出其他几个项目使用的DLL。我们发布的部分内容是发布这些DLL。我使用AfterDropBuild目标。希望我的构建脚本片段中的注释足够清楚,以显示我在做什么。

<!-- Get a reference to the new release address finalizer DLL and the existing published address finalizer DLL  -->
<PropertyGroup>
  <ReleaseDLL>$(DropLocation)\$(BuildNumber)\Release\Address_Finalizer.dll</ReleaseDLL>
  <PublishedFolder>$(SolutionRoot)\3rd Party\bin\PG File Import</PublishedFolder>
  <PublishedDLL>$(PublishedFolder)\Address_Finalizer.dll</PublishedDLL>
</PropertyGroup>

<!-- Check out the published DLL -->
<Exec WorkingDirectory="$(SolutionRoot)" Command='$(TfCommand) checkout /lock:checkout "$(PublishedDLL)"'/>

<!-- Copy release to published -->
<Copy SourceFiles="$(ReleaseDLL)" DestinationFolder="$(PublishedFolder)"/>

<!-- Check in the published DLL -->
<Exec WorkingDirectory="$(SolutionRoot)" Command='$(TfCommand) checkin /override:Automated /noprompt /comment:"$(VersionComment)" "$(PublishedDLL)"'/>