Building A MVC3 Project In Visual Studio Team Services/TFS 2015

In this post I’m going to cover building a MVC3 project in Visual Studio Team Services/TFS 2015.

With the release of Team Foundation Server 2015 Microsoft overhauled the build experience with a completely new build server. The new build experience is way better than the old XAML build and I decided to take it for a spin and share some of the problems or gothas I came across.

There are tons of demos on building MVC projects most of which start with a new MVC project but I wanted to try it out with something more realistic and decided to use a very old MVC3 project I have that has never been successfully built on a build server before. This meant quite a few errors along the way I had to fix first but it didn’t take very long and everything worked fine in the end.

If you want a step by step introduction read this, I will mostly be focusing on the deviation from the happy path in this post and documenting the steps to fix it in case I need it again one day.

First lesson
The retention policy for your builds is 10 days by default so I lost all the build logs from my old builds containing the error message before I got around to writing this post. So most of what I’ll be writing is from memory without screenshots.

Second Lesson
I got this error while restoring packages during the build:

The process cannot access the file NuGet.exe because it is being used by another process.

To fix it was very simple, just update the nuget.exe file in your solution to the newest version.

Third Lesson
I’m using a nuget repository that requires authentication and if you try to run a build you will get error message that it can’t find your packages. To resolve this issue you have to store the credentials in nuget.config for the build server to be able to authenticate against your nuget repository. To do that use the following command:

nuget sources add -Name "YourFeed" 
-source "https://urltonuget/nuget" 
-User username -pass password 
-configFile "Path\To\nuget.config" -StorePasswordInClearText

Sadly this will store it as clear text but the encrypted credentials will only work on the same machine where it was encrypted so you won’t be able to use it on the build server.

Fourth Lesson
In this project all the packages were checked into source control, this is not good practice, it takes up lots of space, pollutes your repository and downloading the project from VSO takes a lot longer. To prevent this from happening use .tfignore files. In this case I placed the file in the root of my project.

Building A MVC3 Project In Visual Studio Team Services/TFS 2015

The contents of the file is very simple.

\packages
!\packages\repositories.config

This will ignore the contents of the packages folder but not the repositories.config since we still need it.

Fifth Lesson
It is also not good practice to include your bin folder in source control, rather use nuget for all your dependencies, in this project which was always built locally all the developers had MVC3 installed on their machines. The project failed to build on the build server since it didn’t (and shouldn’t have MVC3 installed). The fix for this is very simple, install MVC3 as nuget packagein your web project.

Install-Package Microsoft.AspNet.Mvc -Version 3.0.50813.1

Sixth Lesson
Build definitions can become very complex and it is easy to mess it up, luckily VSO will keep track of the changes made to your build definitions, you can even do a diff to see the exact changes. It is like a mini source control for your build definitions.

Building A MVC3 Project In Visual Studio Team Services/TFS 2015

Francois Delport

Published by

Francois Delport

I am a cloud and devops consultant, technology fan and previously a professional C# developer with a keen interest in system design and architecture. Currently I am involved in projects using Azure, the Microsoft stack and DevOps. I am based in Melbourne, Australia. Email: [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *