Along the way, I faced several compatibility and setup issues which caused me several headaches and wall-banging sessions. Although there are many of us sharing similar issues and potential solutions, I faced a hard time to find the right answers and detailed explanations around setting up MSBuild and MSTest to work on a CI server environment.
Because of this, I want to share my findings, hoping that it will help those of you out there dealing with similar situations. I assume that most of this will be particularly relevant for any of you reading my TeamCity series. However, it might help any of you dealing with MSBuild and MSTest in general.
TeamCity MSBuild Issues
If you are still getting errors when your Build runs, it might be because of compatibility issues between your server and development environments.
Whatever you use locally to build your solution, needs to be available on your server environment. It might be, that the server can’t build your solution because it was created with a different version of Visual Studio or is targeting a .NET framework not available or supported in the server.
Keep in mind that what TeamCity does, is simply use the MSBuild application to execute commands to build your .NET projects. This means, that if TeamCity has issues executing MSBuild commands, you should be able to replicate those issues by running the MSBuild commands by yourself. I’ll write more about this in future posts, but just keep it in mind for now.
Fixing MSBuild Compatibility Issues
In my particular case, after setting up the TeamCity Build project and my MVC solution, I still got errors when executing the build step.
The first error was around .NET Framework compatibility. My first MVC solution was targeting .NET Framework 4.5, which was not available in the server. You can either downgrade to .NET Framework 4.0 on your solution if 4.5 is not actually needed, or even better, install the .NET Framework 4.5 on your server. Keep in mind that you might still need a version of TeamCity that supports 4.5. My TeamCity version was a bit older, so I opted to downgrade my MVC solution instead.
So, after modifying the project to target the .NET framework 4.0, and committing the changes I did got different errors during the compilation process. The error relate to the following issue:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found.
The next error was about TeamCity not able to execute the MSBuild step because of missing targets. I had previous projects already working, so I knew the process itself should work.
It turned out that previous projects had been created using Visual Studio 2010 (VS v10.0), but the new MVC project was created using Visual Studio 2012 (VS v11.0). TeamCity was looking for a different version of MSBuild for building the new solution. After a little research, it turns out that the server machine is missing VS 2012 dlls. Since I created the solution in VS 2012, I needed those files.
The solution is to get the files from a machine with VS 2012 and copying them to the machine.
You need to copy the Visual Studio 2012 (v11.0) files to the server. The location should be the following (on 64-bit Windows machines):
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\
After copying the VS 11 files to the server on the correct location, I didn’t have any more issues building the solution.
Hope this helps you. Let me know if it doesn’t work, or if you have any other issues. I might be able to help.