Building .NET 4 projects with Nant

22,154

Solution 1

2010 April 15, ... Update to above correct answer from Eugene, after .net 4 and vs2010 was released.

I downloaded vs2010 and .net 4 runtime. The production version seems to be v4.30319 ie (C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319)

After reviewing http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html, ... I pasted in the text and changed all text from v4.0.20506 to v4.30319 an added text to NAnt.exe.config.

I then updated my nant script to

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

this so my project nant script uses the .net 4 compiler

And this got me a nant build with .net 4 binary ....

Update 2010-06-14: The above was answered with nant-0.85, I upgraded to nant-0.90 and had to add vendor="Microsoft" to framework attribute that is added to nants config. Also, it looks like nant0.9 finds the .net libraries differently, as I had to add something like this to my nant build.xml ...

<property name="framework-get-assembly-directory" value="${framework::get-assembly-directory('net-4.0')}" />
<property name="dotNetReferenceAssemblyPath" value="${framework-get-assembly-directory}\" />

and

<include name="${dotNetReferenceAssemblyPath}System.ComponentModel.DataAnnotations.dll" />

Solution 2

If you want to use nant to build projects targeting .NET 4.0 you'll have to modify NAnt.exe.config and add the net-4.0 target framework and add a <supportedRuntime ... /> line to the <startup> section.

Solution 3

http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html is a full code for .config file for NAnt.

Solution 4

This is pretty similar to these questions/problems:

<msbuild> task or msbuild.exe with NAnt?

Another option would be to directly call MSBuild from an block.

<property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v4.0\MSBuild.exe" />    

<target name="build">
    <exec program="${MSBuildPath}">
            <arg line='"${SolutionFile}"' />
            <arg line="/property:Configuration=${SolutionConfiguration}" />
            <arg value="/target:Rebuild" />
            <arg value="/verbosity:normal" />
            <arg value="/nologo" />
            <arg line='/logger:"C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll"'/>
    </exec>
</target>

Solution 5

NAnt 0.86 and later runs out of the box. As of writing this, I am using 0.91.

When downloading from the net, remember to "unblock" the zip file (reset security zone) before unpacking.

Share:
22,154
plaureano
Author by

plaureano

Updated on July 15, 2020

Comments

  • plaureano
    plaureano almost 4 years

    How do I get nant to build projects that target the .NET 4.0 Framework?

  • Catch22
    Catch22 over 13 years
    Updating the version of NAnt to the latest available version (currently 0.91 Alpha 2) was necessary for me to get this to work (in addition to the build and config changes). btw, did not need the last <include>.
  • James Wiseman
    James Wiseman almost 13 years
    This is what I needed after getting the message Please add a \<framework>\ node with family 'net' and clrversion '4.0.30319' under the 'win32' platform node.