Friday, August 7, 2009

NAnt .NET Framework 4.0 Configuration

4/14/2010 - Updated for .NET 4.0 RTM and feedback from comments.

For anyone who is using NAnt to build their solutions/projects and is also testing out Visual Studio 2010/.NET Framework 4.0 Beta 1, I have included below the .NET 4.0 Framework entry that I added to my NAnt.exe.config file and have been using to successfully compile my projects.

<framework
name="net-4.0"
family="net"
version="4.0"
vendor="MIcrosoft"
description="Microsoft .NET Framework 4.0"
sdkdirectory="${path::combine(sdkInstallRoot, 'bin')}"
frameworkdirectory="${path::combine(installRoot, 'v4.0.30319')}"
frameworkassemblydirectory="${path::combine(installRoot, 'v4.0.30319')}"
clrversion="4.0.30319"
>
<runtime>
<probing-paths>
<directory name="lib/net/2.0" />
<directory name="lib/net/neutral" />
<directory name="lib/common/2.0" />
<directory name="lib/common/neutral" />
</probing-paths>
<modes>
<strict>
<environment>
<variable name="COMPLUS_VERSION" value="v4.0.30319" />
</environment>
</strict>
</modes>
</runtime>
<reference-assemblies basedir="${path::combine(installRoot, 'v4.0.30319')}">
<include name="Accessibility.dll" />
<include name="mscorlib.dll" />
<include name="Microsoft.Build.Engine.dll" />
<include name="Microsoft.Build.Framework.dll" />
<include name="Microsoft.Build.Utilities.dll" />
<include name="Microsoft.Vsa.dll" />
<include name="Microsoft.VisualBasic.dll" />
<include name="Microsoft.VisualBasic.Compatibility.dll" />
<include name="Microsoft.VisualBasic.Compatibility.Data.dll" />
<include name="System.Configuration.dll" />
<include name="System.Configuration.Install.dll" />
<include name="System.Data.dll" />
<include name="System.Data.OracleClient.dll" />
<include name="System.Data.SqlXml.dll" />
<include name="System.Deployment.dll" />
<include name="System.Design.dll" />
<include name="System.DirectoryServices.dll" />
<include name="System.dll" />
<include name="System.Drawing.Design.dll" />
<include name="System.Drawing.dll" />
<include name="System.EnterpriseServices.dll" />
<include name="System.Management.dll" />
<include name="System.Messaging.dll" />
<include name="System.Runtime.Remoting.dll" />
<include name="System.Runtime.Serialization.Formatters.Soap.dll" />
<include name="System.Security.dll" />
<include name="System.ServiceProcess.dll" />
<include name="System.Transactions.dll" />
<include name="System.Web.dll" />
<include name="System.Web.Mobile.dll" />
<include name="System.Web.RegularExpressions.dll" />
<include name="System.Web.Services.dll" />
<include name="System.Windows.Forms.dll" />
<include name="System.Xml.dll" />
</reference-assemblies>
<task-assemblies>
<!-- include MS.NET version-neutral assemblies -->
<include name="extensions/net/neutral/**/*.dll" />
<!-- include MS.NET 2.0 specific assemblies -->
<include name="extensions/net/2.0/**/*.dll" />
<!-- include MS.NET specific task assembly -->
<include name="NAnt.MSNetTasks.dll" />
<!-- include MS.NET specific test assembly -->
<include name="NAnt.MSNet.Tests.dll" />
<!-- include .NET 2.0 specific assemblies -->
<include name="extensions/common/2.0/**/*.dll" />
</task-assemblies>
<tool-paths>
<directory name="${path::combine(sdkInstallRoot, 'bin')}"
if="${property::exists('sdkInstallRoot')}" />
<directory name="${path::combine(installRoot, 'v2.0.50727')}" />
<directory name="${path::combine(installRoot, 'v3.0')}" />
<directory name="${path::combine(installRoot, 'v3.5')}" />
</tool-paths>
<project>
<readregistry
property="installRoot"
key="SOFTWARE\Microsoft\.NETFramework\InstallRoot"
hive="LocalMachine" />
<readregistry
property="sdkInstallRoot"
key="SOFTWARE\Microsoft\.NETFramework\sdkInstallRootv2.0"
hive="LocalMachine"
failonerror="false" />
</project>
<tasks>
<task name="csc">
<attribute name="supportsnowarnlist">true</attribute>
<attribute name="supportswarnaserrorlist">true</attribute>
<attribute name="supportskeycontainer">true</attribute>
<attribute name="supportskeyfile">true</attribute>
<attribute name="supportsdelaysign">true</attribute>
<attribute name="supportsplatform">true</attribute>
<attribute name="supportslangversion">true</attribute>
</task>
<task name="vbc">
<attribute name="supportsdocgeneration">true</attribute>
<attribute name="supportsnostdlib">true</attribute>
<attribute name="supportsnowarnlist">true</attribute>
<attribute name="supportskeycontainer">true</attribute>
<attribute name="supportskeyfile">true</attribute>
<attribute name="supportsdelaysign">true</attribute>
<attribute name="supportsplatform">true</attribute>
<attribute name="supportswarnaserrorlist">true</attribute>
</task>
<task name="jsc">
<attribute name="supportsplatform">true</attribute>
</task>
<task name="vjc">
<attribute name="supportsnowarnlist">true</attribute>
<attribute name="supportskeycontainer">true</attribute>
<attribute name="supportskeyfile">true</attribute>
<attribute name="supportsdelaysign">true</attribute>
</task>
<task name="resgen">
<attribute name="supportsassemblyreferences">true</attribute>
<attribute name="supportsexternalfilereferences">true</attribute>
</task>
<task name="delay-sign">
<attribute name="exename">sn</attribute>
</task>
<task name="license">
<attribute name="exename">lc</attribute>
<attribute name="supportsassemblyreferences">true</attribute>
</task>
</tasks>
</framework>

Again, keep in mind that is what has worked for me. Your mileage may vary. Hope this helps.

34 comments:

Duncan Bayne said...

I'm trying out VS2010 by migrating Wuji.

Next up is actually turning it from a two-hour hack to a well-architected application; will be interesting to test-drive the refactoring support in 2010 and see if it's an improvement over 2008.

I'd like to thank you for this configuration snippet - it took a few minutes to get my NAnt build going again. Greatly appreciated :-)

Paige Cook said...

Duncan,

I am glad that this was helpful. Wuji looks pretty interesting as I am fan of hotkeys and shortcuts, thanks for sharing the link.

Anonymous said...

Thanks! This will be a big help when we make the leap!

Anonymous said...

Thanks Paige. I was trying to setup NAnt on windows 7 with .Net framework 4.0. Your post was helpful to fix my issue.

Anonymous said...

Hi,

I added your 4.0 configuration everything seems to be working except nunit. Do you get a loadtasks error?


[loadtasks] Failure scanning "C:\Development\VioSystem\trunk\library\nant\NAnt.NUnit2Tasks.dll" for extensions. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Paige Cook said...
This comment has been removed by the author.
Paige Cook said...

I do not use the built in Nunit nant task. It is limited to a much older version of nunit. Instead I use the following...


target name="run-unit-tests">
exec program="nunit-console.exe" basedir=".\tools\NUnit\" workingdir=".">
arg value=".\bin\website\bin\Turner.EA.NewsDesk.Test.dll" />
arg value="/xml:.\artifacts\TestResult.xml"/>
arg value="/exclude:UIAutomation" />
/exec>
/target>

(Please note the missing starting < on each line, i was having some formatting issues, so please add those back in)

Note that the .\tools\NUnit directory is relative to where my build file resides and contains appropriate files to get nunit-console.exe to run.

This allows me to update those files to upgrade nunit as I need to.

Also the 2nd argument is to output the results to an xml file, which I then import into my CI process.

Anonymous said...

Thanks for sharing this snippet.

For Visual Studio 2010 RC and NUnit 2.5.3 the vendor attribute must be added to the framework tag (vendor="Microsoft"). Otherwise Nant will fail. Furthermore the version must be changed to 4.0.30128.

Rory said...

Final RTM version is v4.0.30319

A question however...

Does this method compile against CLR 2.0 or CLR 4.0

How might I convince nant to use the 4.0 compiler, yet still target 3.5 (CLR 2.0)

This *is* possible in VS itself and allows new language features to be used whilst still targeting downlevel .Net versions (2.0, 3.0, 3.5)

Anonymous said...

Version that at least for me work with the final 4.0 framework :

http://pastebin.com/KxqFA8T6

Rory said...

So does this generate exes that require .Net 4.0 or 3.5? I'm curious as to how this distinction is affected.

Paige Cook said...

Hi Rory,

What version of the executable that gets generated will depend on what framework your project file is targeting... VS 2010 allows for multi-targeting now.

See this blog post from Scott Guthrie -
http://weblogs.asp.net/scottgu/archive/2009/08/27/multi-targeting-support-vs-2010-and-net-4-series.aspx

All that this config entry allows you to do is use a VS 2010 solution or project to generate your code, as it requires the 4.0 toolset and knowledge of the 4.0 framework, even though it might only be generating 3.5 output.

Rory said...

That's great if I'm using a solution task.. but I'm not... I'm using the csc and vbc tasks.

When I moved from the 2.0 framework to 3.5 I added...
---
[property name="nant.settings.currentframework" value="net-3.5" /]
---

...to my build script.

changing this to...
---
[property name="nant.settings.currentframework" value="net-4.0" /]
---
... allows code using newer syntax to compile, but as I'm not using a project from which the compiler can determine target clr, I'm convinced that I'm getting a 4.0 exe

Any ideas for how to change this ?

Rory said...
This comment has been removed by the author.
Paige Cook said...

Rory,

I do not know how to tell csc or vbc to target a specific framework. I did a quick google search, but did not come up with anything relevant.

Sorry that I could not be of more help.

GiddyUpHorsey said...

The update you made to the config is broken. There are a couple of places where the version still needs to be modified to 4.0.30319 and one where it is incorrectly 4.0.30391.

Paige Cook said...

Thanks for noticing the mistakes, GiddyUpHorsey. I have updated the config file to the correct version number in all locations now.

Unknown said...

You still have this reference clrversion="4.0.20506" which I believe is incorrect.

Also, if you need NAnt to use the 4.0 Framework, I think you need to add the following to the <startup> section at the end:

<!-- .NET Framework 4.0 -->
<supportedRuntime version="v4.0.30319" />

Or at least I did to enable custom code in the script to compile and run.

Paige Cook said...

Thanks Brian. I have updated the missed version number. Also, yes you are correct that the section will need to be updated to use custom code in the script..

Rob Kraft said...

Thank you! I don't know where you found this magic block on XML, but it certainly saved me a lot of work!

Syn_Ack said...

If anyone is wondering, the 2010-05-12 nightly build of NAnt has .NET 4.0 support that needs testing. :)

Sean said...

I just installed nANT .90.

I modified the NAnt.exe.config with the framework tag suggested and added startup element [supportedRuntime version="v4.0.30319" /].

When I attempt to run nant against my csproj with the 4.0 framework I get...
BUILD FAILED
Current target framework is not supported.

Am I missing something? Do I need to upgrade to .91?

Thanks in advance for help.

Syn_Ack said...

Give 0.91 Alpha 1 a try. The purpose of the 0.91 releases is for native .NET 4.0 support.

NAnt 0.90 wasn't designed with 4.0 support.

Sean said...

Found the incompatibility with .net 4 is the solution task. Both .90 and .91 alpha 1 have this short coming (.91 alpha 1 release notes identify this too).

I am using the csc task for now. From what I have seen, I could call msbuild directly too.

Srikant Chokhany said...

I downloaded the latest version of .Nant and Contrib, and just added this line to the top of my build file, and it worked w/o any changes to the nant.exe.config file

Mauricio Scheffer said...

Thanks mate, this just saved me in a legacy project.

Phelan Durham said...

All that this config access allows you to do is use a VS 2010 remedy or venture to produce your rule, as it needs the 4.0 tool set and information of the 4.0 framework.

Unknown said...

The information you have posted for .Net framework is working and I would like to appreciate the post. Download Net Framework 4.5 for Free

henryweston340 said...

You may need to re-install or check your versions of the (dot-) NET framework. As a default, I've been installing every version from 3.5 current for devs I work with. The error you are showing seems to say that most components are from the Framework v 4,
British Dissertation Writers

rmouniak said...


This blog gives very important info about .Net
Dot Net Online Training

Isabell Kiral said...

Thanks for sharing your knowledge with us. This is an interesting post you shared with us. I really liked this post. You are a great writer. I appreciate for your hard work. Get help from coursework writing service , a leading writing company UK.

Dissertation writing service said...

What is NET framework? In this post, we can read about this topic in details. Thanks for sharing your ideas with us.

Raza Dawoodani said...

Such a great article. I will definitely read all of your articles. Marketing Dissertation Help

AL FAHAD IT CONSULTING said...

Great post, Thank you for this help!


Best Zoho implementation services at al Fahad IT consulting. We are the best business software consultants in UAE, KSA, and bahrain.


Best Zoho Integration Services