No Free Time

Because my therapist says I need to let things out

Archive for the ‘tfs’ Category

Team Build 2008 and Visual Studio 2008 Web Deployment Projects

Posted by andrewmyhre on November 18, 2008

I wrote a post earlier this year about how difficult it was to get VS 2005 Web Deployment Projects and Team Build 2005 to play nicely together. Well in the 2008 versions it looks like they put some effort into removing a lot of the friction, so I want to explain how it works now and shout out that it’s much, much better than it used to be.

For the purposes of this example I created a simple website project, a web deployment project, and a basic build definition. There is a lot of information about how to create a team build definition in TFS 2008 so I’ll just gloss over that. The important points here are: a) the inputs (a website and a web deployment project) and b) the outputs.

The Build

The sample solution

1. The sample solution

Creating a build definition

2. Creating a build definition

Select the solution to build

3. Select the solution to build

04

4. Select the platform and configuration (Mixed Platforms and Release)

05

5. Finish

06

6. Create a build agent and enter the drop/staging location for the build

Next I ran a build, and here’s what came out:

The result of the build

The result of the build

 

Notice that within the _PublishedWebsites folder are two folders: ‘Website’ and ‘Website_deploy’. In this example they are identical; if I had set up custom web config replacements then in the ‘Website_deploy’ folder would be a customised web.config file.

If I hadn’t created a web deployment project, the Team Build would still create the ‘Website’ folder and deploy a compiled website. This is important because I believe that didn’t happen with Team Build 2005, it just dumped the compiled assemblies into the Release folder. (Please correct me if I’m wrong).

Deploying where you want

The next thing you (probably) want is to have the deployable website copied from the timestamped drop location to a static location for an IIS website. Here’s how to modify your build script to do this:

1. In the solution explorer, right-click on the build definition and select View Configuration Folder.

Select View Configuration Folder to see where the script is stored in source control

Select View Configuration Folder to see where the script is stored in source control

2. The files will not be downloaded to your machine yet – highlight them, right-click and select Get Latest Version. Now double-click the TFSBuild.proj file to open the build script.

 

Open the build script file

Open the build script file

 

 

3. Now paste the following into the script, just before the closing </Project> tag:

   <PropertyGroup>

    <WebBinariesLocation>$(BinariesRoot)\Mixed Platforms\Release\_PublishedWebSites</WebBinariesLocation>

  </PropertyGroup>

  <Target Name=AfterCompile>

    <Message Text=Copying from out $(WebBinariesLocation) to $(DropLocation)/>

    <RemoveDir Directories=$(DropLocation) Condition=Exists(‘$(DropLocation)’)/>

    <ItemGroup>

      <ProjectSourceFiles Include=$(WebBinariesLocation)\**\*.*/>

    </ItemGroup>

    <Copy

        SourceFiles=@(ProjectSourceFiles)

        DestinationFiles=@(ProjectSourceFiles->’$(DropLocation)\%(RecursiveDir)%(Filename)%(Extension)’)>

      <Output

          TaskParameter=CopiedFiles

          ItemName=SuccessfullyCopiedFiles/>

    </Copy>

  </Target>

What this will do is copy each of the deployment folders in the _PublishedWebsites folder directly into the drop location you specified in step 6 of creating the build definition (above). You don’t need to add anything specific to do with the project (other than the Mixed Platforms\Release path, but this won’t change between build projects). If you set up deployment projects for staging and production you will end up with 3 deployed websites (development, staging and production). Nice!

Obviously for the build to include the script changes you just made you need to check the file back in to source control.

Hope this clears things up.

Posted in CI, tfs | Tagged: , , | 1 Comment »

Howto: Only include part of a project workspace in a TFS 2008 Team Build

Posted by andrewmyhre on July 17, 2008

I’m working on a website with a large design aspect, so we have a lot of .psd files (about 200mb) kicking about the place. We want them source controlled, so they live in the TFS 2008 team project folder in source control. But then our Team Build includes them when downloading the source files, so that quickly fills up our build server’s drive and makes a single build take up to 11 minutes, which is far too long for a basic eCommerce website.

So I trimmed these files from our build process. Here’s what I did:

  1. Copy the .psd files and any other files that aren’t required for a build into a seperate folder in the root of the team project. (All our website/source files are in another folder called ‘Current’, as in the ‘current version’, as opposed to ‘Phase 1′, ‘Phase 2′)
  2. In Team Explorer, right click the build you want to edit and selected Edit Build Definition…
  3. In the Workspace tab, enter the path within source control where you want to start downloading files from. In our case I chose the $/[project]/Current folder, so the /PSDs folder will be ignored and not downloaded.

Now, thanks to the above steps my build history folders are 1/10th the size they were to begin with, and the build process takes less than half the time!

Posted in .net, CI, tfs | Tagged: , , | 2 Comments »

How to delete a team project in Team Foundation Server 2005/2008

Posted by andrewmyhre on July 9, 2008

TFS 2005/2008 both ship with the TfsDeleteProject.exe utility.

Open a command line on your team foundation server and cd to

%program files%\Microsoft Visual Studio 9.0\Common7\IDE (2008)
%program files%\Microsoft Visual Studio 8\Common7\IDE (2005)

Then:

tfsdeleteproject /q /force /server:<tfs server> "<project name>"

Posted in tfs | Tagged: | Leave a Comment »

Where to manage the build location in TFS 2008

Posted by andrewmyhre on May 13, 2008

Until now I’d been confused between the agent working directory, the build service accounts’s temp folder, and the workspace created by Team Build. Do I have to manage all three settings? Do they have to be different? Today I discovered there’s just one location I need to manage for each build agent.

In my efforts to clean up and standardise where projects are being downloaded and built on our build server I discovered that the workspaces automatically created by Team Build don’t actually determine where the build happens. This is because every time TFS performs a build it deletes and recreates a workspace for that build. The source directory path it uses comes from the Build Agent definition:

Build Agent Working Directory

Posted in .net, CI, tfs | Tagged: , , | 1 Comment »

Making Team Build 2005 and Web Deployment Projects play nice: Part 2

Posted by andrewmyhre on May 9, 2008

NOTE: This post applies to TFS 2005 and WDP 2005 only. For TFS 2008 and WDP 2008 the below does not apply. It’s much, much easier to work with Web Deployment Projects in Team Build in 2008 – you can read about it in my updated post.

Right, so yesterday I figured out how to make ASP.Net 2.0/3.5 Website projects work in a Team Build environment using Web Deployment Projects. Today I figured out how to get Web Application Projects to work.

The problem is explained in this thread – take a look at maharik’s post and BradleyB’s reply. maharik was having the same problem I was having, where the Web Deployment project was trying to build the wrong path. At this stage I still don’t fully understand what’s going on (why does the web deployment project need to be pointed to the compiled website?) but I know that it works.

So as background, I’m talking about a .Net 2.0 solution containing a Web Application Project, a Web Deployment Project and zero or more class libraries. The solution is part of a Team Project and I want to set up a Team Build to build the solution.

The Team Build must be set up using the Mixed Platforms as the platform (contrary to what the article I linked to yesterday said – but that article is still correct as far as Website projects are concerned). Choose a configuration (Release/Debug) and make sure your Web Deployment project is configured to build under the same configuration.

Try running the Team Build now. Everything but the WDP should build fine, and you should get errors like this:

error ASPPARSE: Could not load type 'masterpages_default'.

Now you need to follow the directions posted by BradleyB. Find the <SourceWebPhysicalPath>…</SourceWebPhysicalPath> element in your Web Deployment Project file. Comment it out and replace it with:

<SourceWebPhysicalPath Condition=”‘$(OutDir)’ != ‘$(OutputPath)’”>$(OutDir)_PublishedWebsites\WebApplication1</SourceWebPhysicalPath>
<SourceWebPhysicalPath Condition=”‘$(OutDir)’ == ‘$(OutputPath)’”>..\WebApplication1</SourceWebPhysicalPath>

Where ‘WebApplication1′ is the name of your website. Now check in the WDP file.

Now when you run the Team Build again you should find that everything runs successfully, and in your release folder there’ll be a deployment folder with the same name as your Web Deployment Project. Great! Now you can follow the last step from yesterday’s post to add the AfterCompile step to copy the website to your deployment folder.

Nice!

Posted in .net, CI, tfs | Tagged: , , | 2 Comments »

Make Team Build and Web Deployment Projects play nice

Posted by andrewmyhre on May 9, 2008

Update: Part 2, Web Application Projects.

The thing I like about Web Deployment Projects is the easy configuration of things like compilation (I like to compile to a single assembly), configuration section replacement (so, so much easier than setting this up in NAnt) and deployment. I also really like Team Builds, because they’re so easy to set up (compared to NAnt and CruiseControl.Net). But they don’t have the customisation features of Web Development Projects that I mentioned above. Plus the deployment option in a Team Build is absolutely useless to me, because it deploys the web project to a different folder every time. So I need a way to combine the two configuration features plus make sure the website is deployed to a specific folder on our development web server.

Initially I thought this would be really easy, in fact I expected that the Visual Studio team had specifically designed Team Build and WDPs to compliment each other. Ummmmm not exactly, it seems. I had loads of trouble getting the two to work together, with loads of builds failing due to stupid problems… usually due to the WDP losing its context and building the wrong stuff.

The best guide I found on the subject is this one. It explains that ASP.Net Websites and Web Application Projects are treated differently by Team Build (not why, just that they are) and that you need to use specific, different platform configurations.

To get my ASP.Net Website project (I haven’t tried Web Application Projects yet) working I created a WDP for it. I specified that it should build under the Release configuration, then checked in my solution. I then created a Team Build which targeted the Release|Mixed Platforms configuration. At that point I ran the team build and happily everything came up green, including the WDP.

To my dismay though, although the Web Deployment Project ran, it wouldn’t copy the build to the folder I specified in the WDP configuration. It just wouldn’t do it, and I have a feeling it’s something like the Team Build overriding the drop folder property that the WDP picks up.

The bottom line is that you need to manually override a build task to perform the copy yourself. This isn’t that difficult, and I’m happy to say it’s a step that I can expect other the other developers I work with to perform without needing to know too much about what’s going on.

So the final step was to modify the Team Build project file slightly. First I added the following property group, just below the closing </ProjectExtensions> element:

<PropertyGroup>
    <!-- change this to the name of the Web Deployment Project -->
    <BuildFileName>Engelbart2</BuildFileName>
    <!-- change this to location where you want the website deployed to -->
    <DeployLocation>\\engelbart\wwwroot\projects\tequila\digital playground\buildtest\staged</DeployLocation>

    <!-- don't worry about this -->
    <WebBinariesLocation>$(SolutionRoot)\..\Binaries\Mixed Platforms\Release\_PublishedWebSites\$(BuildFileName)</WebBinariesLocation>
  </PropertyGroup>

Then I added the following below the last </ItemGroup> element (I don’t think it actually matters where you put this):

<!-- deploy the compiled site to where we want it to go -->
  <Target Name="AfterCompile">
    <MakeDir Directories="$(DeployLocation)" />
    <!--<Exec Command="xcopy /y /e '$(WebBinariesLocation)' '$(DeployLocation)'"/>-->
    <ItemGroup>
      <ProjectSourceFiles Include="$(WebBinariesLocation)\**\*.*"/>
    </ItemGroup>
    <Copy
        SourceFiles="@(ProjectSourceFiles)"
        DestinationFiles="@(ProjectSourceFiles->'$(DeployLocation)\%(RecursiveDir)%(Filename)%(Extension)')">
      <Output
          TaskParameter="CopiedFiles"
          ItemName="SuccessfullyCopiedFiles"/>
    </Copy>
  </Target>

This works because your web deployment project is build as part of the team build into it’s own special folder. So for instance I could have team builds called ‘Development’, ‘Staging’ and ‘Production’, each with special web.config settings which the WDP would handle for me. The output from Team Build will be three websites, each in a distinct folder with the correct configuration. It wouldn’t be difficult to modify the above script to copy three seperate releases.

Hope this clears up some mysteries…..

Posted in CI, tfs | Tagged: , , | 1 Comment »

Change TFS Build Agent Build Location

Posted by andrewmyhre on March 13, 2008

When you create a TFS 2008 build, there are three build locations you need to be aware of.

First is the location that the build agent ‘gets’ the source to for compilation. You can specify this when creating the Build Agent – just set the Working directory to the location you want the source to be downloaded to. Normally this will be set to the windows temp folder for the account the build service is running under.

The second location is where the build is compiled. This is defined within the Build Definition as the Workspace for the build. TFS copies the source files from the ‘working directory’ to the ‘workspace’ before compilation. It is compiled into a new sub-folder with the same name as the build definition.

Thirdly, you have the option of specifying a build drop location. Your compiled build will be copied here into a new sub-folder, datestamped and versioned by the build number. I haven’t worked out yet how to instruct the build script to deploy a compiled website to a static location. Would love to know if anyone can shed any light!

Posted in CI, tfs | Tagged: , , | 1 Comment »

A Nice Day With Microsoft

Posted by andrewmyhre on February 5, 2008

I spent the day today at a Developer Day seminar at Microsoft Campus in Reading with my line manager at my work. We were shown demonstrations of the gamut of Team System functionality; it was very cool.

I had a good idea that we could use the Developer and Test editions to full advantage, but I had a preconception that the Database and Architect editions were just there to complete a ’suite’, and didn’t provide much in the way of helpful functionality.

Turns out the Database edition provides some pretty comprehensive database schema management tools, including schema comparisons, difference scripting, schema version control (a big sell for me) and DB unit testing. I had figured we’d be best to just get into bed with RedGate and build the workings of version control ourselves, but I’m really impressed with what they’ve put together.

Likewise the Architect edition. You have the ability to create two types of model: environment and application. You begin by creating the environment model, including firewalls, DMZ, server platforms (down to service pack versions) and the network interfaces between. Then you design your overall application model – website, web services (including method stubs, return types etc), and databases. You can also provide the base platform requirements of each box in the diagram (Windows 2003 Server with .Net 2.0 and SP 2 perhaps). Finally you have the application generate a project with
method stubs, and then visually map the application components on to the server infrastructure. Visual Studio with then analyse your deployment scenario and inform you of any potential problems.

You could do all of that with pen and paper, and it’s certainly a lot cheaper. It’s the one we’re interested in the least. But it’s cool, and would have come in very handy on the last project we attempted. One of the constraints was that there had to be 3 (count ‘em) seperate proxy web services between our web app and the external post code lookup service we were leveraging. We now have these three services sitting in our project with the ambiguous names of ‘WSProxy1′, ‘WSProxy2′, and ‘WSProxyExternal’ – how nice it would be if this could have been planned out visually with some more thought, or better tools. I shudder to think how a fresh contractor will react when they try to debug results through those services.

So I think we’re going to go ahead and purchase TFS 2008, a few Developer editions and a Test edition. Possibly a DB edition, but I wouldn’t be suprised if we hold off for the time being.

Just a quick word about the Developer edition… not much different to 2005 but TFS 2008 support for Build Definitions (were Build Types) is much, much improved. You can now set up a massive range of configuration options with your build, you can edit an existing build (how that didn’t make it into the 2005 release I’ll never know), and you can set triggers/schedules with the same power as with a Windows scheduler task (which is what it will be under the hood). Also they have released a set of power tools which add real continuous integration of the style of CCNet.

All in all a fantastic day and I’m glad to have taken part. Very appreciative that my work is making a real effort to find and implement the right tools for the job, in fact putting their money where their mouth is. I think I’m in a good spot for 2008.

Incidentally I work for these guys. Oh, and we’re looking for permanent people, if you know anyone.

Posted in tfs | Tagged: | Leave a Comment »

Some TFS, Continuous Integration Related Links

Posted by andrewmyhre on February 4, 2008

Beginning to look into some of my notes from the weekend with a bit more depth. Starting with Continuous Integration, especially regarding TFS.

Some links:

Continuous Integration Using Team Foundation Build – MSDN
Provides an example project on your TFS server which provides a simple CI interface. Source not available unfortunately!

TFSBuildLab

My thoughts, shares … with .Net and Microsoft
Not sure who maintains this blog yet but it’s .Net and TFS 2008 related.

Continuous Integration in Team Build for OrcasTips for upgrading from TFS 2005 to 2008 – Grant Holiday

TFS 2008: A basic guide to Team Build 2008

Why and How to build a Continuous Integration Environment for the .NET platform

Continuous Integration with Cruise Control.NET and Draco.NET by Justin Gehtland

Continuous Integration by Martin Fowler

Boy, this is tough… as soon as I look at one resource I find a dozen more. I’ll never get through my notes at this rate.

Posted in tfs | Tagged: | Leave a Comment »

MVC Not Ready For TFS?

Posted by andrewmyhre on January 9, 2008

High expectations this year. I want to have at least a couple of commercial MVC website under my belt by 2009, and I want to be using Team Foundation 2008. Part of this will be to make use of Web Deployment Projects combined with Team Builds. What would be great is if I could have the team server spitting out nicely labelled development, staging and production builds of our sites, and if I could configure the config file changes using web deployment projects. Also I would like it to produce metrics around unit tests, integration test and interface tests, and anything else that would be useful (code metrics? haven’t explored this fully yet). I want our projects managers/testers to be able to know what build they’re looking at and easily get a summary of the changesets involved in that build.

So that’s the plan. We are currently running TFS 2005, but the documentation says that VSTS 2008 and TFS 2005 are compatible, so what I’m going to do first is set up a ‘Sandbox’ MVC project in it’s own Team Project space, for us to play with and try things out.

So started by creating a new Team Project, then a new ASP.Net MVC Web Application and Test project (makes sense – want to try out the built in unit testing functionality).

Then I choose the project in TFS I want to use as the repository.

At this stage everything is created and ready to check in, so I perform a solution check-in. All looks good, I can see padlocks next to all my files. But if I close and re-open the solution, I get the message:

The project ‘MvcApplicationTest’ is under source control. This version of Visual Studio .NET does not support source controlled projects. Any changes that you make to this project will not be propagated to source control.

Strange! And now the test project is no longer source-controlled. If I create a build to run these tests on the build server it won’t have any of the project files to compile and run.

To clarify, I’m using Visual Studio Team System 2008 RTM. Anyway, I’ve tried a couple of things, like deleting the test project and adding a new test project. Trouble is I can’t write tests against the MVC controllers due to some weird issue – I can’t add a reference to the version of System.Web.Extensions.dll referenced by the MVC project (3.6.0.0) to the test project. It’s in the GAC, but doesn’t appear in the components list (I see 3.5.0.0, the version that ships with VS 2008). So I can’t even create my own test projects.

Bit of a worry and I hope it gets addressed when MVC goes into full release…

Posted in .net, mvc, tfs | Tagged: , , | 1 Comment »