Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify MSBuild version in nant script?

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.

like image 975
Mike Avatar asked Feb 27 '13 15:02

Mike


People also ask

How do I know what version of MSBuild I have?

There is no way to determine which version of MSBuild was used. There is no days in the executable that says which version was used and nothing in them specific to MSBuild to use as a trail of breadcrumbs to determine it either. You dont even need MSBuild to build an executable.

What is MSBuild version?

MSBuild 17.1.0. This version of MSBuild shipped with Visual Studio 2022 17.1. 0 and . NET SDK 6.0. 200.

How do I run MSBuild script?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.


2 Answers

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.

like image 107
Mike Avatar answered Sep 22 '22 06:09

Mike


Older versions of NAnt/NAntContrib default to v2.0.

Sounds like: Nant msbuild task with .net 4.0 rc

like image 22
Kevin Richardson Avatar answered Sep 19 '22 06:09

Kevin Richardson