Building .NET 4 projects with Nant
Asked Answered
H

8

36

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

Harmless answered 1/8, 2009 at 3:7 Comment(0)
S
23

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" />
Spelling answered 14/4, 2010 at 15:38 Comment(1)
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>.Romalda
K
13

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.

Katakana answered 1/8, 2009 at 3:14 Comment(0)
S
5

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

Suffumigate answered 20/1, 2010 at 12:36 Comment(1)
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.Cowbell
W
2

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>
Willingham answered 4/8, 2009 at 19:23 Comment(0)
Z
1

I used all of the answers above and still ran into some weird build errors: "error MSB6006: "AL.exe" exited with code 128". Error not helpful at all. I did some googling and came up with few answers. Here are the links: msdn help and asp.net forums

I wrestled with that error for a full day, studying the "detailed" and "diagnostic" logs, but all it did is pointing me to the assembly that failed building. No specific error. I could not even duplicate it on my local box. Finally, I decided to try the suggestion about resource files naming convention in the second link (asp.net forums) and... alleluia! my build started working. I don't know what's up with the build failing because of the resource name, still working on that, but my immediate goal was to get the build working.

Hope this helps someone else out there.

Zajac answered 4/5, 2010 at 19:6 Comment(0)
N
1

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.

Neves answered 10/5, 2012 at 9:44 Comment(0)
U
0

Just to put the info there so i could find it again, to build C++ projects without modifying the PATH environement variable and creating LIB/LIBPATH/INCLUDE variables or running nant from vsvars32, something like that is needed in Nant config file :

<project>
    <readregistry
        property="WindowsSdkDir"
        key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\InstallationFolder"
        hive="LocalMachine"
        failonerror="true" />

    <readregistry
        property="installRoot"
        key="SOFTWARE\Microsoft\.NETFramework\InstallRoot"
        hive="LocalMachine" />
    <readregistry
        property="sdkInstallRoot"
        key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools\InstallationFolder"
        hive="LocalMachine"
        failonerror="false" />
    <readregistry
        property="vs10Win32Tools"
        key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-Win32Tools\InstallationFolder"
        hive="LocalMachine"
        failonerror="false" />      
    <readregistry
        property="vcInstallDir"
        key="SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VC\ProductDir"
        hive="LocalMachine"
        failonerror="true" />
    <readregistry
        property="vs10dbghelp"
        key="SOFTWARE\Microsoft\VisualStudio\10.0\Setup\Dbghelp_path"
        hive="LocalMachine"
        failonerror="true" />

    <setenv name="PATH" value="${path::combine(vcInstallDir, 'bin')};${vs10dbghelp};${sdkInstallRoot};${vs10Win32Tools};${environment::get-variable('PATH')};" />
    <setenv name="INCLUDE" value="${path::combine(WindowsSdkDir, 'include')};${path::combine(vcInstallDir, 'atlmfc/include')};${path::combine(vcInstallDir, 'include')};${environment::get-variable('INCLUDE')}" />
    <setenv name="LIB" value="${path::combine(WindowsSdkDir, 'lib')};${path::combine(vcInstallDir, 'atlmfc/lib')};${path::combine(vcInstallDir, 'lib')};${environment::get-variable('LIB')}" />
    <setenv name="LIBPATH" value="${path::combine(installRoot, 'v4.0.30319')};${path::combine(installRoot, 'v3.5')};${path::combine(WindowsSdkDir, 'lib')};${path::combine(vcInstallDir, 'atlmfc/lib')};${path::combine(vcInstallDir, 'lib')};${environment::get-variable('LIBPATH')}" />
</project> 

The registry path are the one of VS2010 as the corresponding SDK is taking it's time...

Uvea answered 27/4, 2010 at 12:45 Comment(0)
M
0

I had similar issue for 4.5, this solved my issue:

http://www.donnfelker.com/nant-sdkinstallroot-has-not-been-set/

I have a 64 bit machine but .net is installed as 32 bit. The sdkInstallRoot is not able to find the correct path. I checked in my registry editor to find the correct path and replaced the entry in nant.exe.config.

I replaced:

<locatesdk property="sdkInstallRoot" minwinsdkver="v7.0A" minnetfxver="4.0" maxnetfxver="4.0.99999" failonerror="false" />

with this:

<readregistry
                            property="sdkInstallRoot"
                            key="SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools\InstallationFolder"
                            hive="LocalMachine"
                            failonerror="false" />
Moldboard answered 14/7, 2016 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.