S h o r t S t o r i e s

// Tales from software development

MSBuild 3.5: /toolsversion and ToolsVersion

with one comment

One of the changes between the 2.0 and 3.5 versions of the .NET Framework is the addition of the FindInList MSBuild task. A few days ago I thought I’d have a quick play with this task to see exactly what it offers.

Strangely, my build script kept failing with the following error message:

C:\temp\test.proj(14,3): error MSB4036: The "FindInList" task was not found.
Check the following:
1.) The name of the task in the project file is the same as the name of the task class.
2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks
files located in the "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" directory.

There are two things to note. Obviously, the error indicates that the FindInList task cannot be found but the reference to version 2.0.50727 is odd. I confirmed that I was executing MSBuild from the c:\WINDOWS\Microsoft.NET\Framework\v3.5 folder instead of c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. Having done this, I dismissed the version in the message as an error in the 3.5 version of MSBuild. 

Next, I checked that the MSBuild.Common.Targets file specified an entry for FindInFiles. It did, so then I used Reflector to check that the task was implemented and exposed as a public class in the Microsoft.Build.Tasks.v3.5.dll assembly. Finally, I changed the task reference in the build script so that it was fully qualified. The problem remained and I was running out of ideas.

On a hunch, I checked the MSBuild command line arguments. The 3.5 version of MSBuild has several new arguments including one called /toolsversion. This looked promising…

A bit of experimenting showed that even when executing MSBuild 3.5, the version 2.0 tasks library is used unless the /toolsversion argument is used to specify that the 3.5 version tasks should be used. This explains why the error message referred to the version 2.0.50727.

The /toolsversion argument is intended to override the new ToolsVersion attribute of the project’s Project element. If the ToolsVersion attribute is not specified then version 2.0 is assumed.

So, the correct way to write a version 3.5 MSBuild project file is to specify the ToolsVersion attribute:

<Project DefaultTargets = "Full" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
Advertisements

Written by Sea Monkey

December 22, 2008 at 9:00 pm

Posted in MSBuild

Tagged with

One Response

Subscribe to comments with RSS.

  1. Very useful note.
    Do you have sample code to paste… I’m trying to find some string within an item…
    thanks

    Sahas

    August 25, 2009 at 3:22 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: