Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to get TFS to output each project to its own directory?

Tags:

msbuild

tfs

I'm putting a large codebase into Team Foundation Server. I would like the build process to create a "ready to deploy" build of our projects.

The normal way we've been doing this is to have each project's output be in its own folder. So, for example, we wind up with something like

C:\project1\             assembly1.dll             assembly2.dll             project1.exe             project1.exe.config C:\project2\             assembly2.dll             assembly3.dll             project2.exe             project2.exe.config C:\project3\             assembly1.dll             assembly3.dll             project3.exe             project3.exe.config 

Which is the way we like it.

TFS, though, seems to want to stick everything in the same directory.

C:\output\           assembly1.dll           assembly2.dll           assembly3.dll           project1.exe           project1.exe.config           project2.exe           project2.exe.config           project3.exe           project3.exe.config 

which, although it saves some amount of disk space (the assemblies are only there one time each) is not how we want it.

What's the best way to specify where TFS/MSBuild should put the output files? Do I need to edit sln/csproj files individually to achieve this or can I do it in the TFSBuild.proj file? (i.e., in a MSBuild-specific file)

like image 455
Tom Kidd Avatar asked Mar 30 '09 20:03

Tom Kidd


1 Answers

I just blogged another method here:

http://mikehadlow.blogspot.com/2009/06/tfs-build-publishedwebsites-for-exe-and.html but if you can't be bothered to follow the link, here it is in full:

It’s generally good practice to collect all the code under your team’s control in a single uber-solution as described in this Patterns and Practices PDF, Team Development with TFS Guide. If you then configure the TFS build server to build this solution, it’s default behaviour is to place the build output into a single folder, ‘Release’.

Any web application projects in your solution will also be output to a folder called _PublishedWebsites\. This is very nice because it means that you can simply robocopy deploy the web application.

Unfortunately there’s no similar default behaviour for other project types such as WinForms, console or library. It would be very nice if we could have a _PublishedApplications\ sub folder with the output of any selected project(s). Fortunately it’s not that hard to do.

The way _PublishedWebsites works is pretty simple. If you look at the project file of your web application you’ll notice an import near the bottom:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" /> 

On my machine the MSBuildExtensionsPath property evaluates to C:\Program Files\MSBuild, if we open the Microsoft.WebApplication.targets file we can see that it’s a pretty simple MSBuild file that recognises when the build is not a desktop build, i.e. it’s a TFS build, and copies the output to:

$(OutDir)_PublishedWebsites\$(MSBuildProjectName) 

I simply copied the Micrsoft.WebApplication.targets file, put it under source control with a relative path from my project files and changed _PublishedWebsites to _PublishedApplications and renamed the file CI.exe.targets. For each project that I want to output to _PublishedApplications, I simply added this import at the bottom of the project file:

<Import Project="<your relative path>\CI.exe.targets" /> 

You can edit CI.exe.targets (or whatever you want to call it) to do your bidding. In my case, the only change so far is to add a couple of lines to copy the App.config file:

<Copy SourceFiles="$(OutDir)$(TargetFileName).config" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" /> 

There’s a lot of stuff in Microsoft.WebApplication.targets that’s only relevant to web applications and can be stripped out for other project types, but I’ll leave that as an exercise for the reader.

like image 180
Mike Hadlow Avatar answered Sep 23 '22 00:09

Mike Hadlow