Using Nant with .NET 3.5

With the release of Nant 0.86 Beta 1, .NET 3.5 and Silverlight 2.0 are supported.  However, I had to make a few minor adjustments in order for Nant to work on our build servers.  After running a known-good build script, on the build server, we started receiving the following error:

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

 
I did a quick search and found some information about this on Jeffery Palermo's site.  A few people were experiencing the same problem, but the only solution they had was to use an older configuration section from this blog post.  I was not satisfied with this solution so I kept investigating.

As far as I can tell, this has something to do with machines that do not actually have Visual Studio installed on them.  If you manually install the .NET 3.5 SDK you may actually install a different version than the one that comes with Visual Studio 2008.

If you receive this error, look in your Nant.exe.config file and scroll down to the framework node that has an name attribute of net-3.5.  Inside of this framework node, you will see a project node with the following data:

   1:  <readregistry
   2:      property="installRoot"
   3:      key="SOFTWARE\Microsoft\.NETFramework\InstallRoot"
   4:      hive="LocalMachine" />
   5:  <readregistry
   6:      property="sdkInstallRoot"
   7:      key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKNetFxTools\InstallationFolder"
   8:      hive="LocalMachine"
   9:      failonerror="false" />

The main thing here is to verify that these registry keys actually exist. Open up regedit and navigate to the keys indicated by the config file, if they do not match, you should correct them in the Nant.exe.config file.

I had to modify the second key to the following on our build server:

SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.1\WinSDKNetFxTools\InstallationFolder

It's easy to fix once you figure it out, Enjoy!


Feedback

# re: Using Nant with .NET 3.5

Gravatar Great!,
I had the same problem and this post helped me fix it.

Dan 6/12/2008 6:41 AM | Daniel

# re: Using Nant with .NET 3.5

Gravatar You're my hero for the day! :)

I was fighting this problem for hours a few weeks ago, and gave up. I ended up manually calling the MSBUild from nant's <execute> task. I updated the nant.exe.config like you show and i can call the <msbuild> task appropriately, now.

thanks!
7/8/2008 5:41 PM | Derick Bailey

# re: Using Nant with .NET 3.5

Gravatar Glad I could help! 7/8/2008 8:47 PM | Page Brooks

# Automating .NET 3.5 Builds With NAnt 0.86 - Object Reference Error When Targetin

Gravatar 7/9/2008 2:10 PM | ThoughtStream.Create(me);

Comments have been closed on this topic.