4

I am using team city to call a nant script, currently this nant script is very simplistic and only calls an msbuild task on a single project in the solution.

The build is failing, it looks like msbuild 3.5 is being called, but it is incorrectly calling the csc.exe from the .net 2.0 folder. Since we are using .net 3.5 language features the compilation fails.

Looking at the csproj file, both the ToolsVersion and TargetFrameworkVersion are both set to use 3.5. What would be causing msbuild to pick the wrong version of csc.exe?

ilivewithian
  • 19,476
  • 19
  • 103
  • 165

3 Answers3

8

MSBuild uses a Toolset of tasks, targets, and tools to build an application. Typically, a MSBuild Toolset includes a microsoft.common.tasks file, a microsoft.common.targets file, and compilers such as csc.exe and vbc.exe. To ensure MSBuild invokes the correct C# compiler (csc.exe), specify the Toolset in the ToolsVersion attribute on the Project element in the project file. The following example specifies that the project should be built by using the MSBuild 4.0 Toolset.

<Project ToolsVersion="4.0" ... </Project>

More information pertaining to the ToolsVersion attribute can be found here: http://msdn.microsoft.com/en-us/library/78f4aasd.aspx

0

Do you have the 2.0 version of csc directly in your path, perhaps?

What happens when you run msbuild from a Visual Studio 2008 Command Prompt?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • There is nothing in the path. If I run msbuild on the server it runs fine. There's a clue in there somewhere. Hmm, I guess it's either teamcity or nant and not msbuild after all. – ilivewithian Aug 18 '10 at 09:25
0

You can directly point which msbuild you want to use in nant script by declaring:

<!-- Initial path to use MSBuild from .NET Framework 3.5 -->
<property name="MSBuildApp" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />

And then execute build via msbuild:

<exec failonerror="true" program="${MSBuildApp}" verbose="true">
        <arg value="${SlnDir}\${SlnFile}" />
        <arg value="/t:Rebuild" />
        <arg value="/p:Configuration=${SlnConfig}" />
    </exec>

Or you can point to proper .NET framework version when running NANT script:

nant CreateYouProjectTask -t:net-3.5 -buildfile:BuildYourProject.build

Leszek Wachowicz
  • 1,015
  • 1
  • 14
  • 24