How to Build and Deploy an ASP.NET Application with Team Build

- J.D. Meier, Jason Taylor, Alex Mackman, Prashant Bansode

If you want to build a solution that contains only ASP.NET Web applications, you must ensure that you choose the appropriate configuration. When creating the build type, when you select the configuration and the platform, make sure that the platform is set to .NET and that the Configuration is set to Debug:

To build a solution that contains only ASP.NET Web applications projects
  1. Run the New Team Build Type Creation Wizard.
  2. Give the build a name.
  3. Select the solution that contains only the ASP.NET Web application.
  4. Select the appropriate configuration.
  5. Click the Platform drop-down list and select .NET as the platform.
  6. Specify the location information for the build type.
  7. Choose the tests and code analysis rules to run.
  8. Save the build type by selecting Finish.

If you are building a solution that contains both ASP.NET Web applications and other .NET projects, you must set the platform type to Mixed Platforms.

To build a solution that contains ASP.NET Web applications and other .NET projects
  1. Run the New Team Build Type Creation Wizard.
  2. Give the build a name.
  3. Select the solution that contains only ASP.NET Web applications and other projects.
  4. Select the appropriate configuration.
  5. Click the Platform drop-down list and select Mixed as the platform.
  6. Specify the location information for the build type.
  7. Choose the tests and code analysis rules to run.
  8. Save the build type by selecting Finish.

You will find the compiled binaries in the drop location under {BuildType}\{Configuration Name}\{Platform}\_PublishedWebsites

Deploying a Web application to Internet Information Services (IIS) is not supported natively by Team Build. If you want to deploy the application to IIS as part of the team build, you have two choices: you can: add a custom step to the build type, or you can use a Web Deployment Project.

If you are at the start of a Team Project, examine the Web Deployment Project option to see if you can use this option in your development. If you already have existing Web sites, using Web Deployment Projects may disrupt application development. Consider using an MSBuild post-build step instead. In both cases, you must ensure that the service account used to run the build is a member of the local administrators group to allow it to create a virtual directory in IIS.

To use a post build step to deploy your Web application
  • Download the SDC Tasks Library from Codeplex at http://www.codeplex.com/sdctasks
  • Check out the Team Build type that you are going to use to deploy the Web application.
  • Extract the file Microsoft.Sdc.Tasks.dll from the downloaded zip file into the folder where you checked out the build type.
  • Add the DLL to source control and check it in.
  • Amend the TFSBuild.proj file so that the build copies the files to the correct directory, and then create that directory as a virtual directory as follows:
    • Add a <PropertyGroup> element specifying the location of the compiled Web application:

 <PropertyGroup>
  <WebBinariesLocation>$(SolutionRoot)\..\Binaries\.NET\Release\_PublishedWebSites\MyWebSite</WebBinariesLocation>
 </PropertyGroup> 

  • Add two UsingTask elements that add a references to the CreateVirtualDirectory and DeleteVirtualDirectory tasks:

 <UsingTask TaskName="Microsoft.Sdc.Tasks.Web.WebSite.CreateVirtualDirectory" AssemblyFile="Microsoft.Sdc.Tasks.dll" />
 <UsingTask TaskName="Microsoft.Sdc.Tasks.Web.WebSite.CreateVirtualDirectory" AssemblyFile="Microsoft.Sdc.Tasks.dll" /> 

  • Add an AfterCompile target to create the virtual directory and copy the files into that directory:

 <Target Name="AfterCompile">
  <MakeDir Directories="C:\Deploy\MyWebsite" />
  <CreateVirtualDirectory VirtualDirectoryName="MyWebSite" Path="C:\Deploy\Website" />
  <DeleteVirtualDirectory VirtualDirectoryName="MyWebSite" />
  <Exec Command="xcopy /y /e $(WebBinariesLocation) C:\Deploy\MyWebsite"/>
</Target> 

  • Save the file and commit it to the source control repository.

If you run the team build, it will now build the Web application, create a virtual directory, and copy the Web application to that directory.

To use a Web deployment project
  1. Download and install the Visual Studio 2005 Web Deployment Projects onto your client computer.
  2. Download and install the Visual Studio 2005 Web Deployment Projects onto your build server.
  3. Open the solution containing the Web application.
  4. Click the Build menu and then select Add Web Deployment Project…
  5. Specify the name and location of the deployment project.
  6. In Solution Explorer, right-click the Web Deployment Project and then select Property Pages.
  7. In the dialog box, choose the Configuration that Team Build should build (Debug or Release).
  8. In the Deployment section, select the Create an IIS virtual directory for the output folder check box and then specify the virtual directory name.
  9. Click OK.
  10. Check the solution changes into source control.

If you run the team build containing this solution, it will build the Web application and create a virtual directory in the directory where the Web application is built. This will be Build Directory}\{Team Project Name}\{Build Type}\Binaries\{Configuration Name}\{Platform}\_PublishedWebSite\{Web Deployment Project Name.

Additional Resources

Last edited Jul 26, 2007 at 6:04 AM by prashantbansode, version 1

Comments

FreeToDev Jul 31, 2008 at 5:43 PM 
IIS7 tasks are available here: http://www.codeplex.com/freetodevtasks

tathorp May 29, 2008 at 8:19 PM 
Also, this creates it under the IIS Default Web Site. How does one make it a standalone site?

tathorp May 29, 2008 at 8:17 PM 
Any idea why this documentation says to first create the virtual directory and then delete it? Shouldn't this be delete then create?

sjsingh Apr 25, 2008 at 11:56 AM 
Hi,
I followed the same procedure as given in here but i got the below error:

------------------------------------------------------------------------------------
A task error has occured.
//path//\TFSBuild.proj(17,5): error : Message = The system cannot find the path specified.
//path//\TFSBuild.proj(17,5): error :
//path//\TFSBuild.proj(17,5): error : VirtualDirectoryName = MyWebSite
//path//\TFSBuild.proj(17,5): error : Path = C:\Deploy\Website
//path//\TFSBuild.proj(17,5): error : MachineName = localhost
//path//\TFSBuild.proj(17,5): error : FtpSiteName = Default FTP Site
//path//\TFSBuild.proj(17,5): error : AccessFlags = <String.Empty>

--------------------------------------------------------------------------------------------------
Also i found that the place - sources and binaries folder where empty.
Can you tell me why is all this happening???