How to specify MSBuild version in nant script

msbuildmsbuild-4.0nant

I have a nant script that in one of its targets uses the msbuild tags to build a Visual Studio 2010 solution.

The problem is it fails when it hits this point, the error is:

Solution file error MSB5014: File format version is not recognized.  MSBuild can only read solution files between versions 7.0 and 9.0, inclusive.

Failed to start MSBuild.

External Program Failed:  C:\Windows\Microsoft.NET\Framework\v2.0.50727\msbuild.exe (return code was 1)

The error makes sense, if it's calling the .NET 2.0 version of MSBuild it won't compile the VS2010 solution. However, I can't figure out how to get it to call the right version of MSBuild.

If I run 'where MSBuild' (from the same VS2010 Command Prompt that the build script failed in), I get:

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
 C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe

If I run 'msbuild /version' (again, same window) I get:

 Microsoft (R) Build Engine version 4.0.30319.17929
 [Microsoft .NET Framework, version 4.0.30319.18034]
 Copyright (C) Microsoft Corporation. All rights reserved.

 4.0.30319.17929

So everything looks like it should be using the 4.0 version, but it's not. Any idea what gives? I know I've addressed this issue before, but can't remember what it was to save my life.

Best Answer

I appreciate the answers, and I know skolima's would work, the solution ended up being as simple as the addition of this tag:

    <property name="nant.settings.currentframework" value="net-3.5"/> 

Thanks again.