Tuesday, September 21, 2010

NAnt and the .Net 4 error

NAnt threw this odd error today.

The reason for it being odd was the version of the .Net framework being used in the call: .Net 4.0, instead of 3.5.  While I have 4.0 installed, I was trying to build a 3.5 project.

A little searching and I soon had a good guide of how to build 4.0 projects using NAnt, but this wasn't the solution to my problem.

Why 4.0?

Now it is possible to tell NAnt which framework to use, the -t: switch from the command line or in the main NAnt.exe.config file. I tried, and failed. NAnt threw the same error.

I wanted to stop NAnt using .Net 4.0, but how? Well, near the bottom of the config file is a list of supported Frameworks, of which 4.0 is one.

Removing the entry for 4.0 fixed the problem. Certainly this is a quick fix as NAnt has a problem with .Net 4.0 on my PC, but not a problem to be fixed today.


Thanks to Rawdon for mentioning the path to the configuration file. You can find this in %InstallLocation%\NAnt\bin\NAnt.exe.config

Also from the comments. Paul Stewart has found the cause of the problem and written it up in this post.


Seth said...

Thank you! This one had me totally stumped as we were migrating all of our dev boxes to brand new images of Windows Server 2008 and Visual Studio 2010

keithbloom said...

@Seth. Glad it was of help.

Rawdon said...

Sweet ! Spent ages typing to work this out, for anyone unsure the config file you want to change is in your nant bin foler e.g. C:\ProgramFiles\NAnt\bin\NAnt.exe.config

keithbloom said...

Yep, a niggly bug. Thanks for the adding the path to the config file.

Deep said...

Pretty nice fix. Thanks for the help. Pretty nice finding.

Paul said...

I don't know if you ever got to the bottom of this problem, but this blog post held the answer for me: http://www.byteblocks.com/post/2011/01/19/Nant-Build-Error-SystemSecurityPermissionsFileIOPermission.aspx

vvakar said...

Thanks a bunch!

sankara said...

nice work.Thanks saved me lot of time

JustSmith said...

Awesome. I'm looking to use Nant to help with deployments and this issue was the only thing standing in my way.