4

我已经成功安装了 Team Foundation Server 2008,并创建了一个单独的构建服务器(因为我的构建当前失败,所以它可以工作)。

我已经创建了一个简单的“Hello World”Web 应用程序(都是标准的 Default.aspx 页面)并将它放在 TFS 的源代码控制系统中。

以前,在 TFS 之前,我只需预编译我的 Web 应用程序并将结果复制到预先创建的 IIS 虚拟目录中。

在 Google 上搜索了一段时间,我还没有找到关于通过 TeamBuild 将应用程序从 TFS 源正确部署到指定测试 Web 服务器的分步指南。我知道 MS Build 属于这个等式,所以任何指导都会有所帮助。

我已经看到了有关部署的点点滴滴,其中提到了 _PublishedWebSites 等文件夹,但还没有一步一步地找到任何东西。

4

3 回答 3

4

我在 TFSBuild.proj 文件的 AfterDropBuild 目标中成功使用了 exec 任务。

<Target Name="AfterDropBuild>
    <Exec Command="xcopy /Y /E &quot;$(DropLocation)\\$(BuildNumber)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites\MyWebsite1\*.*&quot; &quot;\\server\MyWebsite1\&quot;" />
    <Exec Command="xcopy /Y /E &quot;$(DropLocation)\\$(BuildNumber)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites\MyWebsite2\*.*&quot; &quot;\\server\MyWebsite2\&quot;" />
</Target>

请注意,需要正确设置权限,TFS 服务用户才能访问您要复制到的服务器上的文件夹。

于 2009-03-10T16:34:18.050 回答
4

Firstly you should be using WebDeployment projects as this will do a lot more compilation and checking of your code and markup. See here for more info.

I have 4 environments setup DV [Development], PY [Prototype], PP [Pre-Production], PD [Production] all matching branches in TFS. Each of these has also has an entry in the sln configuration manager where you can setup what projects are required to be build and the build flags.

Once that is setup correctly you can then start setting up deployment scripts. I prefer use MSbuild to deploy as it will give you a lot more fine-grained approach to deployment. MSbuild is a bit strange to start with however once you get the hang of it it's quite powerful.

My deployment script which is added to the TeamBuild config is below. Basically as you can see I do a bit of post-build cleanup before I copy to the live servers. I also use 2 MSbuild frameworks (imported at the top).

<Import Project="$(MSBuildExtensionsPath)\Microsoft\SDC Tasks - Release 2.1.3155.0\Microsoft.Sdc.Common.tasks"/>
<Import Project="$(MSBuildExtensionsPath)\FreeToDev\MSBuild Tasks Suite 3.5\FreeToDev.MSBuild.tasks"/>

<PropertyGroup>
    <InetpubFolder>\\PathToInetPub</InetpubFolder>
    <AppFolder>AppFolder</AppFolder>
    <AppFolderPath>$(InetpubFolder)$(AppFolder)</AppFolderPath>
    <WebDeployName>WebDeployProjectName</WebDeployName>
    <Debug>0</Debug>
    <AppConfiguration>DV</AppConfiguration>
</PropertyGroup>

<Target Name="AfterDropBuild">
    <Message Text="Begin Release to $(AppConfiguration) Webserver" />
    <Message Text="DropLocation = $(DropLocation)" />
    <CallTarget Targets="PostBuildCleanUp"  />
    <CallTarget Targets="DeployApp"  />
</Target>

<Target Name="DeployApp">

    <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">
        <Output TaskParameter="DropLocation" PropertyName="DropLocation"></Output>
    </GetBuildProperties>

    <PropertyGroup>
        <CodeDropLocation>$(DropLocation)\$(AppConfiguration) Release</CodeDropLocation>
    </PropertyGroup>

    <ItemGroup>
        <AppFilesToDelete Include="$(AppFolderPath)\**\*.*" Exclude="$(AppFolderPath)\Library\*.*;$(AppFolderPath)\App_Offline.htm;$(AppFolderPath)\jobs\**\*.*" />
    </ItemGroup>

    <ItemGroup>
        <FilesToDeploy Include="$(CodeDropLocation)\$(AppFolder)\**\*.*" Exclude="" />
    </ItemGroup>

    <Copy SourceFiles="$(CodeDropLocation)\$(AppFolder)\App_Offline[RemoveToActivate].htm" DestinationFiles="$(AppFolderPath)\App_Offline.htm" OverwriteReadOnlyFiles="true"/>

    <Message Text="Deleting files in $(AppFolderPath)" />
    <Microsoft.Sdc.Tasks.File.DeleteFiles Files="@(AppFilesToDelete)" Force="true" Condition="$(Debug)==0" />

    <Message Text="Copy $(CodeDropLocation)\$(AppFolder) to $(AppFolderPath)" />
    <Copy Condition="$(Debug)==0" SourceFiles="@(FilesToDeploy)" DestinationFiles="@(FilesToDeploy->'$(AppFolderPath)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true"/>

    <Message Text="Deploy to $(AppConfiguration) Completed" />
    <Microsoft.Sdc.Tasks.File.DeleteFiles Files="$(AppFolderPath)\App_Offline.htm" Force="true" />

    <OnError ExecuteTargets="ErrorHandler" />
</Target>

<Target Name="ErrorHandler">
    <Message Text="Error encountered!!" />
</Target>

<Target Name="PostBuildCleanUp">

    <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">
        <Output TaskParameter="DropLocation" PropertyName="DropLocation"></Output>
    </GetBuildProperties>

    <PropertyGroup>
        <CodeDropLocation>$(DropLocation)\$(AppConfiguration) Release</CodeDropLocation>
    </PropertyGroup>

    <ItemGroup>
        <PostBuildCleanUpFilesToDelete Include="$(CodeDropLocation)\*.*;$(CodeDropLocation)\bin\*.xml;$(CodeDropLocation)\bin\*.pdb"/>
    </ItemGroup>

    <RemoveDir Directories="$(CodeDropLocation)\_PublishedWebsites\Web" />
    <Microsoft.Sdc.Tasks.File.DeleteFiles Files="@(PostBuildCleanUpFilesToDelete)" Force="true">
        <Output TaskParameter="DeletedFiles" ItemName="FilesThatWereDeleted" />
    </Microsoft.Sdc.Tasks.File.DeleteFiles>
    <Message Text="The files that were removed were @(FilesThatWereDeleted)" />

    <FTDFolder TaskAction="Move" Path="$(CodeDropLocation)\_PublishedWebsites\$(WebDeployName)" TargetPath="$(CodeDropLocation)\$(AppFolder)"/>

    <RemoveDir Directories="$(CodeDropLocation)\_PublishedWebsites" />

    <RemoveDir Directories="$(CodeDropLocation)\$(AppFolder)\WebDeploy" />

    <OnError ExecuteTargets="ErrorHandler" />
</Target>

Obviously you will need to modify to your system setup. Also it clears down the target folder before it starts to copy the new build accross. This is to make sure they system is clean but obviously you will need to add anything that you need to keep to the ExcludedFiles list.

I also have a folder for each environment in the main application project. This holds the web.config replacements (another feature of WebDeployment projects) and any other environement specifc files.

It will be a long process to get it working correctly but hopefully this will get you started!! (Obviously if you choose this apporach!)

于 2009-04-14T19:24:40.313 回答
2

这可以直接通过构建脚本来完成,Vertigo Software 的人通常是解决许多此类 TFS 问题的最佳信息来源……不幸的是,他们的博客文章在谷歌上的排名通常不那么高。这是本网站的创建者之一杰夫·阿特伍德 (Jeff Atwood) 的作品:

团队构建后复制 Web 文件

于 2009-03-10T15:41:25.493 回答