NAnt fix for .Net 3.5

22 September 2008

I created a build script for a .Net 3.5 project today and received the following error

  Target framework: Microsoft .NET Framework 2.0
    Target(s) specified: build
      [echo] getting into the script

      [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()

When I changed the nant.settings.currentframework property in the build script from "net-3.5" to "net-2.0" this error went away. (Of course I received an error from the .Net 2.0 version of MSBuild since it was trying to compile .Net 3.5 code, but it let me know that there was a problem within NAnt dealing with the "net-3.5" setting)

I didn’t want to dig through the NAnt source code to figure out what the problem was, so I did some googling and found the following blog entry from Jeffrey Palermo. In the comments a person shared he was receiving the same error and a few comments below that a person shared that they updated the "net-3.5" framework section in the Nant.exe.config file with Jeffrey’s version that is located at this link.

I reran the build and NAnt worked like a charm.

If I had a lot of ambition I would try to figure out the exact cause for this error and fix my build script, but today I just don’t have that much ambition.

 | Posted by admin | Categories: Hacks, nant |