如何使用Team Build部署ASP.NET Web应用程序?

时间:2021-02-03 03:38:52

I have managed to install Team Foundation Server 2008 and I created a separate build server (which works because my builds are currently failing).

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

I have created a simple "Hello World" Web application (all is the standard Default.aspx page) and have it in TFS's source control system.

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

Previously, prior to TFS, I'd simply precompile my web application and xcopy the results on to a pre-created IIS Virtual directory.

以前,在TFS之前,我只是预编译我的Web应用程序并将结果xcopy写入预先创建的IIS虚拟目录。

Scouring Google for a while, I have yet to find a step by step guide on correctly deploying an application from TFS Source via TeamBuild to a designated test web server. I know MS Build falls into this equation, so any guidance would be helpful.

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

I have seen bits and pieces about deployments, with folders such as _PublishedWebSites mentioned, but have yet to find anything step by step.

我看过有关部署的点点滴滴,提到了_PublishedWebSites这样的文件夹,但还没有一步一步找到任何东西。

3 个解决方案

#1


I've had success using a exec task in the AfterDropBuild target in the TFSBuild.proj file.

我已成功在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>

Note that the permissions need to be setup correctly for the TFS service user to access the folder on the server your are copying to.

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

#2


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.

首先,您应该使用WebDeployment项目,因为这将进行更多的编译和检查您的代码和标记。有关详细信息,请参见此处

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.

我有4个环境设置DV [开发],PY [原型],PP [预生产],PD [生产] TFS中所有匹配的分支。其中每个都在sln配置管理器中有一个条目,您可以在其中设置需要构建的项目和构建标志。

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.

一旦设置正确,您就可以开始设置部署脚本。我更喜欢使用MSbuild进行部署,因为它会为您提供更细粒度的部署方法。 MSbuild开始时有点奇怪,但是一旦掌握了它,就会非常强大。

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

我的部署脚本添加到TeamBuild配置中,如下所示。基本上你可以看到我在复制到实时服务器之前做了一些后期构建清理。我还使用2个MSbuild框架(在顶部导入)。

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

显然,您需要修改系统设置。此外,它会在开始复制新构建之前清除目标文件夹。这是为了确保它们的系统是干净的,但显然你需要添加你需要保存到ExcludedFiles列表中的任何内容。

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.

我还为主应用程序项目中的每个环境都有一个文件夹。这包含web.config替换(WebDeployment项目的另一个功能)和任何其他environement特定文件。

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

让它正常工作将是一个漫长的过程,但希望这会让你开始! (显然,如果你选择这个apporach!)

#3


This can be done via the build scripts directly, the Vertigo Software guys usually are the best source of info for a lot of TFS questions like this...unfortunately their blog posts don't usually rank that high on google. This one's by Jeff Atwood, one of the creators of this site:

这可以通过构建脚本直接完成,Vertigo软件人员通常是许多TFS问题的最佳信息来源......不幸的是,他们的博客文章通常不会在谷歌上排名那么高。这是由本网站的创建者之一杰夫阿特伍德提出的:

Copying Web Files After a Team Build

在团队构建后复制Web文件

#1


I've had success using a exec task in the AfterDropBuild target in the TFSBuild.proj file.

我已成功在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>

Note that the permissions need to be setup correctly for the TFS service user to access the folder on the server your are copying to.

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

#2


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.

首先,您应该使用WebDeployment项目,因为这将进行更多的编译和检查您的代码和标记。有关详细信息,请参见此处

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.

我有4个环境设置DV [开发],PY [原型],PP [预生产],PD [生产] TFS中所有匹配的分支。其中每个都在sln配置管理器中有一个条目,您可以在其中设置需要构建的项目和构建标志。

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.

一旦设置正确,您就可以开始设置部署脚本。我更喜欢使用MSbuild进行部署,因为它会为您提供更细粒度的部署方法。 MSbuild开始时有点奇怪,但是一旦掌握了它,就会非常强大。

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

我的部署脚本添加到TeamBuild配置中,如下所示。基本上你可以看到我在复制到实时服务器之前做了一些后期构建清理。我还使用2个MSbuild框架(在顶部导入)。

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

显然,您需要修改系统设置。此外,它会在开始复制新构建之前清除目标文件夹。这是为了确保它们的系统是干净的,但显然你需要添加你需要保存到ExcludedFiles列表中的任何内容。

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.

我还为主应用程序项目中的每个环境都有一个文件夹。这包含web.config替换(WebDeployment项目的另一个功能)和任何其他environement特定文件。

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

让它正常工作将是一个漫长的过程,但希望这会让你开始! (显然,如果你选择这个apporach!)

#3


This can be done via the build scripts directly, the Vertigo Software guys usually are the best source of info for a lot of TFS questions like this...unfortunately their blog posts don't usually rank that high on google. This one's by Jeff Atwood, one of the creators of this site:

这可以通过构建脚本直接完成,Vertigo软件人员通常是许多TFS问题的最佳信息来源......不幸的是,他们的博客文章通常不会在谷歌上排名那么高。这是由本网站的创建者之一杰夫阿特伍德提出的:

Copying Web Files After a Team Build

在团队构建后复制Web文件