First of all, if you are running a 64 bit server, MSBuild usually defaults to use its 64 bit version. The problem is that "Microsoft.VisualStudio.Settings.11.0.dll" that comes with Visual Studio 2012 SDK has only a 32 bit version. So when the TFS build agent runs, you will get errors saying that "The system cannot find the file specified. File name: 'Microsoft.VisualStudio.Settings.11.0, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'...". The file is actually right there in the Visusal Studio SDK common assembly folder. you can even add it to the GAC. It will not help because it is a 32 bit assembly. You will have to switch to the 32 bit MSBuild in your build definition:
|Build Definition Setting for Building LightSwitch Applications|
The problems for building LightSwitch applications do not end there, unfortunately. Once you get pass the DLL problem, you will most likely see that the build agent starts to complain that the server output is missing: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v3.0\Microsoft.LightSwitch.targets (108): Could not copy the file "...\obj\Release\Application.Server.dll" because it was not found.
Usually TFS build agent would build the release configuration of a solution. With LightSwitch projects (*.ls3proj) files, there are actually two sub-projects; one for the server and one for the HTML client. When building the LightSwitch project using MSBuild, the selected build configuration information gets lost. It never gets passed to the two sub-projects. When no build configuration is specified, these projects default to debug builds. When the time comes for the "ls3proj" to copy the output files, they are created in the wrong configuration, any you will get the errors described above.
A quick fix for this is to change the default configuration of these sub-projects. In the
|Server Project File|
Similarly, you can change the HTML client default to release as well. In the
|HTML Client Project File|
Of course, a better solution would be to fix "Microsoft.LightSwitch.Build.Tasks.targets" file to pass selected configuration to the sub-projects. That is a little more complicated. Since I do not need to create LightSwitch projects very often, fixing the project files is a much simpler solution.