C# – Simple HelloWorld build script

.net-3.5cnantnet

I have a simple HelloWorld application that I'm trying to build using NAnt. However, even with the simplest of build files, I still cannot get it to work. Below is my HelloWorld.build file.

<?xml version="1.0"?>
<project name="Hello World" default="build">
<property name="nant.settings.currentframework" value="net-3.5"/>
<target name="build">
    <echo>Hello</echo>
    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"         
        commandline="HelloWorld /t:Clean /p:Configuration=Debug /v:q" workingdir="." /> 
</target>

Here are the results.

C:\webdev\HelloWorld>c:\nant-0.86-beta1\bin\NAnt.exe build
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/webdev/HelloWorld/HelloWorld.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: build

 [property] Target framework changed to "Microsoft .NET Framework 3.5".

BUILD FAILED

INTERNAL ERROR

System.NullReferenceException: Object reference not set to an instance of an object.
   at NAnt.Core.FrameworkInfo.get_Version()
   at NAnt.Core.Project.UpdateTargetFrameworkProperties()
   at NAnt.Core.Tasks.PropertyTask.ExecuteTask()
   at NAnt.Core.Task.Execute()
   at NAnt.Core.Project.InitializeProjectDocument(XmlDocument doc)
   at NAnt.Core.Project.Execute()
   at NAnt.Core.Project.Run()

Please send bug report to nant-developers@lists.sourceforge.net.

Total time: 0 seconds.

Also, when I try to manually set the .NET framework to use, I get the following:

C:\webdev\HelloWorld>c:\nant-0.86-beta1\bin\NAnt.exe -t:net-3.5
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Microsoft .NET Framework 3.5 (net-3.5) is not installed, or not correctly configured.

    Object reference not set to an instance of an object.

However, the config file does have an entry for .NET 3.5 .This is with NAnt-0.86-beta and Visual C# 2008 Express Edition. Am I completely off track? If so, does anyone perhaps have a template build file that can be reused?

Thank you.

Best Answer

Well I tried your build file on a very simple console application and aside from tweaking the command line arguments it all works just fine for me.

Have you tried to reinstall the .net framework 3.5 as it definately looks like thats missing (what happens if you try and execute msbuild from the cmd line with the exact path from the 3.5 framework directory ?)

<?xml version="1.0"?>
<project name="HelloWorld" default="build">
    <property name="nant.settings.currentframework" value="net-3.5"/>
    <target name="build">    
        <echo>Hello</echo>       
        <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" commandline="HelloWorld.sln /t:Clean /p:Configuration=Debug /v:q" workingdir="." />
    </target>
</project>

the output for my project looks like this

NAnt 0.86 (Build 0.86.2898.0; beta1; 08/12/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/Documents and Settings/krystan/My Documents/Visual Studio
2008/Projects/HelloWorld/test.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: build


build:

     [echo] Hello
     [exec] Microsoft (R) Build Engine Version 3.5.30729.1
     [exec] [Microsoft .NET Framework, Version 2.0.50727.3082]
     [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
     [exec]

BUILD SUCCEEDED

Total time: 0.2 seconds.
Related Topic