Friday, March 04, 2011

VS2010 deployments using TFS2010 Build Server

Placeholder for TFS2010 Build notes


My TFS2010 Build Server Config


Enable web.config Transforms for TFS 2010 Builds

Found this solution on Kevin Daly's Blog. Unfortunately it involves editing the project/solution files to make it work.


  1. Make a master list of build targets for the projects in your solution. Assuming all build targets will be used in at least one web.config transform, you'll need to keep track of them for use later in the TFS build definition.
  2. In your TFS build definition, go to the Process section and add the build configurations from step 1 to the "Items to build->Configurations to Build" section. Be sure to define the configurations exactly as you have then in your solution.
  3. In the solution explorer, unload the project you want to add the transform to, then right click the project name and edit the project file. Add the following XML chunk just before the last </Project> tag:
    <Target Name="AfterBuild" Condition="$(IsAutoBuild)=='True'">
    <ItemGroup>
    <DeleteAfterBuild Include="$(WebProjectOutputDir)\Web.*.config" />
    </ItemGroup>
    <TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="$(WebProjectOutputDir)\Web.config"/>
    <Delete Files="@(DeleteAfterBuild)" />
    </Target>
  4. Edit the TFS build definition again. In the "process" section, go to "Advanced->MSBuild Arguments" and add the following parameter
    /p:IsAutoBuild="True"

That should do the trick. Run the build and if it succeeds, open the drop folder and browse into the "_PublishedWebsites" folder. Find your project and check the web.config to confirm it produced the right results.

Create Web Deploy Package with TFS

To create a Web Deploy package for your project in the drop folder, you need to throw a few more MSBuild parameters into the TFS build definition.

/P:CreatePackageOnPublish=true /P:DeployOnBuild=true

These switches just create the package on the filesystem. Also, your project "Package/Publish Web" settings should be configured in VS2010 (usually the defaults are fine).


Build Server Errors

  • ... The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
    This error means that the build box is missing some files required to perform the project MSBuild. In this case, I was trying to perform a web.config xml transform for a VisualStudio 2010 web application project. I was able to fix the issue by installing VS2010 on the build box. I'm guessing its a safe bet to install your typical workstation development tools on the build box to make sure that all your build requirements are met.

Resources

No comments: