Simple HelloWorld build script

不羁的心 提交于 2019-12-13 00:24:23

问题


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.


回答1:


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.



回答2:


Some times this error is because the build server does not have the sdk installed.

Try installing the windows sdk. You can download it on the Microsoft Download Center

Additional steps may be needed to get nant to recognize the sdk, please refer to this Page Brook's Blog Post




回答3:


There is a bug in Nant 0.86, see http://sourceforge.net/tracker/index.php?func=detail&aid=1986551&group_id=31650&atid=402868 for more info.

You can download Nant nightly build (currently nant-0.86-nightly-2009-05-05) which has this bug fixed.



来源:https://stackoverflow.com/questions/1348552/simple-helloworld-build-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!