Wednesday 23 June 2010

Building without Visual Studio


If you don’t have Visual Studio installed, maybe because this is a build server, then you will almost certainly get msbuild errors because it cannot find some tool or other from the Windows SDK.

Like:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1835, 9):
error MSB3454: Tracker.exe is required to correctly incrementally generate resources
in some circumstances, such as when building on a 64-bit OS using 32-bit MSBuild.
This build requires Tracker.exe, but it could not be found. The task is looking for
Tracker.exe beneath the InstallationFolder value of the registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A. To solve the
problem, either: 1) Install the Microsoft Windows SDK v7.0A or later. 2) Install
Microsoft Visual Studio 2010. 3) Manually set the above registry key to the correct
location. Alternatively, you can turn off incremental resource generation by setting
the "TrackFileAccess" property to "false".

You may also get a similar message regarding LC.EXE.

The v7.0A version of the Windows SDK is installed when you install Visual Studio 2010 and is expected by the .Net 4.0 version of msbuild. However, you don’t seem to be able to get it as a separate download!

A bit of Googling shows a few “solutions. Such as adding “TrackFileAccess=false” as a configuration option for msbuild (http://bradwilson.typepad.com/blog/2010/05/working-around-build-error-msb3454.html).

This works fine for the TRACKER.EXE problem but not for the LC.EXE version.

Here’s my solution:

  1. Download the v7.1 version of Windows SDK (for .Net 4.0 and good for all version of Windows)
    http://www.microsoft.com/downloads/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b&displaylang=en
    Other versions are available from the Windows SDK MSDN Developer Center (http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx)
  2. This is a web installer. If you decide to go find the full ISO of the SDK it’s around 1.6GB. The web installer lets you only select the bits you want and should download/install in a few minutes.
  3. Run winsdk_web.exe you downloaded above. Click through until you get to the “Installation Options” page.
  4. De-select everything except the .NET Development – Tools. The page should look like this

  5. On Windows 2008 server it will let you also completely unselect the Intellisense assemblies too
  6. Select next until it starts installing.
    Even on a slow connection it should only take a few minutes.
  7. Lastly you need to convince msbuild to use this version of the SDK
  8. On the Start menu you will have a “Microsoft Windows SDK v7.1” folder
  9. Select “Windows SDK 7.1 Command Prompt”
  10. Enter the following commands
    > cd Setup
    > WindowsSdkVer –version:v7.1

    See http://msdn.microsoft.com/en-us/library/ff660764.aspx (Configuring Visual Studio for Visual C++ Development with the Windows SDK) for info
  11. Done. Msbuild will now be able to find the tools it needs

You will also run into problems is you’re trying to compile web apps with an error like

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Simply copy the folder “C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0” from your dev machine with VS2010 installed onto your build server.

YMMV but this is what works for me.
Good luck