Skip to main content

TFS2010: Publishing solution projects to their own directories

When looking to automate a TFS2010 build one of the first issues that most people seem to encounter is that all the binaries of each project in a solution end up in the same "bin" directory. The forum post TFS 2010 BUILD SERVER: Can not keep folder tree in the drop location ? details the solution; which is changes to both the CSPROJ file and the workflow template that is called by your build. Note: each CSPROJ file in your project needs to be updated as the workflow loops through the solution finding all the referenced projects.. The answer in the forum post has everything about what is needed but not why, which can be a bit confusing if you're just starting out with TFS / workflow.

The image to the left is the section of the workflow that is changed. The workflow variable "OutputDirectory" is defined within the scope of "Compile and Test for configuration" (highlighted in green). The value of "outputDirectory" is assigned (highlighted in red) and typically just includes the the build name + the build version (so Trunk_20120220.1 would be the first time the trunk build has run on 20th Feb 2012). For the default template the value of "outputDirectory" is assigned to the input argument "OutDir" of the "Run MSBuild for project" step (highlighted in blue). In the default template it is for this reason why all the binaries of all the projects end up in a single directory. The first documented change is to modify the properties of "Run MSBuild for project", the value of "outputDirectory" is no longer passed in the input argument "OutDir" but is assigned to the input argument of "CommandLineArguments" instead.

The code below duplicates the change to the "CommmandLineArguments" input argument referred to in the forum post but highlights the interaction of "OutputDirectory". The value of which is passed as the value of a variable whose name is not important - as long as it matches the reference you add to your CSPROJ file.

"/p:SkipInvalidConfigurations=true {0} /p:TfsProjectPublishDir=""{1}""",
MSBuildArguments, outputDirectory)

The code below shows the corresponding change made to the CSPROJ file. Similar to the previous section the important interaction with the workflow changes are highlighted. The name you use can be any unique variable name that you like that does not clash with existing workflow / environment variables. The change does need to be made to all CSPROJ files and for all configurations that you need to build. In this instances we can build both debug and/or release and we will end up with separate binary directories for each. For each CSPROJ file change the projectname value to a value unique to the project in question.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath Condition=" '$(TfsProjectPublishDir)'=='' ">bin\debug\</OutputPath>
<OutputPath Condition=" '$(TfsProjectPublishDir)'!='' ">$(TfsProjectPublishDir)\projectname\</OutputPath>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath Condition=" '$(TfsProjectPublishDir)'=='' ">bin\release\</OutputPath>
<OutputPath Condition=" '$(TfsProjectPublishDir)'!='' ">$(TfsProjectPublishDir)\projectname\</OutputPath>

If you're not familiar with CSPROJ files, they are just XML based files that MSBuild uses to build the referenced project. The "Condition" attribute determines whether that XML element (and any children) are passed to MSBuild. So the first "PropertyGroup" is only present if configuration and platform equal Debug and AnyCPU (respectively), the second if it is equal to Release and AnyCPU. As should be apparent this conditional logic implies that only one of these PropertyGroups should ever be presented to MsBuild and they contain the configuration/platform specific values needed for the build. This conditional logic is how MsBuild behaviour changes between the IDE and TFS. If TfsProjectPublishDir is defined then that "OutputPath" node is included, otherwise the default more familiar "OutputPath" node is presented to MsBuild.


Popular posts from this blog

Mocking HttpCookieCollection in HttpRequestBase

When unit testing ASP.NET MVC2 projects the issue of injecting HttpContext is quickly encountered.  There seem to be many different ways / recommendations for mocking HttpContextBase to improve the testability of controllers and their actions.  My investigations into that will probably be a separate blog post in the near future but for now I want to cover something that had me stuck for longer than it probably should have.  That is how to mock non abstract/interfaced classes within HttpRequestBase and HttpResponseBase – namely the HttpCookieCollection class.   The code sample below illustrates how it can be used within a mocked instance of HttpRequestBase.  Cookies can be added / modified within the unit test code prior to being passed into the code being tested.   After it’s been called, using a combination of MOQ’s Verify and NUnit’s Assert it is possible to check how many times the collection is accessed (but you have to include the set up calls) and that the relevant cookies have …

Do "Task Hours" add anything in Scrum (Agile)?

What do task hours add to the overall process in scrum?This was a question that has arisen from all team members in both instances that I've helped teams switch over to scrum. The benefits of artifacts like the comparative story point estimation, the 2 week sprints, stand-ups and the end of sprint demo have been self evident to the team, but as one I think every team member has expressed dismay when it comes to task planning and estimating each task in hours. Left unchecked there is a natural tendency for people to actually begin to dread the start of each sprint purely due to the task planning session.In my current role we've been lucky to investigate this further as a team.The team sat down to discuss the problems it was experiencing with estimating tasks in hours and the following common themes appeared:It is hard: Maybe it shouldn't be, but time estimation is hard! Story points are comparative and abstracted making them easier to determine, but time estimate is gen…

Why do my Android Notification only appear in the status bar?

I'm definitely getting back into Android development, I'm remembering that feeling of 'Surely this should be easier than this!'. All I wanted to do was to schedule a local notification which behaved similar to a push notification pop-up. That is, as well as showing the small icon in the status bar I wanted it to pop up on screen to notify the end user. All seems fairly easily, I found this code for how to schedule a notification. That all worked perfectly, apart from the notification would only appear in the status bar. Searching around I found loads of different answers / solutions, mostly all saying the same thing:It only worked if you used 'NotificationCompat.Builder' in place of 'Notification.Builder', orYou had to set the priority to 'NotificationCompat.PRIORITY_HIGH'As usually happens, none of these solutions worked for me until I added in the missing piece of the jigsaw:- '.setDefaults(Notification.DEFAULT_ALL)'. For me this…