Saturday, 5 November 2011

TIP: Running NAnt 0.91 on Windows 7

Since I've joined a company several months back which is primarily .NET based, I've been working with a recent version of NAnt on 32-bit Windows XP Pro SP3, which I didn't get to install and configure as it was a hand-me-down desktop. While deciding to do a little experimentation with NAnt 0.91 at home on 64-bit Windows 7, I discovered that it wasn't just as easy as downloading it, unzipping it to a directory, putting it on the system path and running it. Naturally, without observing the RTFM rule, I tried the above and encountered two errors. After RTFM, I was still none-the-wiser : ) Here I explain what these command line errors are and how to resolve them. Note that the my Windows 7 UAC (User Account Control) sub-system and et cetera have default settings on my system.

First Error: .NET Framework Related
 

C:\Development\nant-tests>nant
 

NAnt 0.91 (Build 0.91.4312.0; release; 22/10/2011)
Copyright (C) 2001-2011 Gerry Shaw
http://nant.sourceforge.net


INTERNAL ERROR
 

Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
 

    Could not load file or assembly 'System.Web, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
 

For more information regarding the cause of the build failure, run the build again in verbose mode.
Please send a bug report (including the version of NAnt you're using) to nant-developers@lists.sourceforge.net

 
C:\Development\nant-tests>


After having a look at the requirements section of the NAnt 0.91 manual, I still found things a little confusing - for example, I thought I had .NET installed as the following directory existed C:\Windows\Microsoft.NET\Framework64\v4.0.30319 and similar for Framework directory for the 32-bit version but this was not the case. Unbeknownst to me, I only had the client profile installed which can be seen by opening up the Programs and Features window in the Control Panel and searching for Microsoft .NET Framework 4 Client Profile. After a bit of online perusing and a pinch of intuition, I found that I needed to download and install the dotNetFx40_Full_x86_x64.exe executable from the Microsoft website and once done, Microsoft .NET Framework 4 Extended appeared under the Programs and Features window in the Control Panel and the above .NET Framework error was resolved.

Second Error: Windows 7 Security Related 


C:\Development\nant-tests>nant
 

log4net:ERROR XmlConfiguratorAttribute: Exception getting ConfigurationFileLocation. Must be able to resolve ConfigurationFileLocation when ConfigFile and ConfigFileExtension properties are not set.
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
   at System.Security.CodeAccessPermission.Demand()
   at System.AppDomainSetup.VerifyDir(String dir, Boolean normalize)
   at log4net.Util.SystemInfo.get_ConfigurationFileLocation()
   at log4net.Config.XmlConfiguratorAttribute.ConfigureFromFile(Assembly sourceAssembly, ILoggerRepository targetRepository)
 

The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
Internet

 
Unhandled Exception: System.Security.SecurityException: Request for ConfigurationPermission failed while attempting to access configuration section 'nant'. To allow all callers to access the data for this section, set section attribute 'requirePermission' equal 'false' in the configuration file where this section is declared. ---> System.Security.SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
   at System.Security.CodeAccessPermission.Demand()
   at System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca)
   --- End of inner exception stack trace ---
   at System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at NAnt.Console.ConsoleStub.Framework.GetRuntimeFramework()
   at NAnt.Console.ConsoleStub.Main(String[] args
 

C:\Development\nant-tests> 

In addition to the above being spat out into the command line, Windows 7 will pop up a window to let you know that NAnt has stopped workingIf you click on the View problem details link, you can see that one of the Problem Signatures reads System.Security.Security - this is a clue as to what the issue is. After searching online again, I found that the problem was Windows 7 security related in that the downloaded NAnt 0.91 zip file needed additional security related configuration to be performed: before extracting, one must right click on the zip file, select Properties and under the General tab, click the button labelled Unblock, then click OK on the Properties window. Now, extract the file to your desired location, ensure it is on the system path, open a new command line and NAnt should run successfully.

Note that when using NAnt Contrib tasks with the loadtasks task, ensure that the zip which the Contrib tasks was extracted from was unblocked as above. If not, either delete the current Contrib directory, unblocking the Contrib zip and extracting again or configure the the DLL used in loadtasks by unblocking it separately, just like the zip.

25 comments:

  1. This post helped me. Thank you!

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Yup, just had to say another thanks for the tip on the blocked files -- I made it through the .NET Framework 4.0 nonsense, but hadn't yet figured out the blocked files. All my ACL's looked fine, but didn't think about the stupid IE zone data... ARrrrrgg.

    Rather than unpacking the ZIP again, I just used the old Streams utility to strip that metadata off. Streams.exe -s -d "c:\program files (x86)\Nant" and it was solved in about 50msec.

    ReplyDelete
    Replies
    1. Hi AlbuquerqueFX,

      Thank you very much for your advice with Streams.exe, my pc actually with restricted access that can't even see the unblock button, or do the default unblocking by registry.

      I was almost frustrated until I tried the Streams.exe, thank you very much!

      Lydia

      Delete
  4. Hi AlbuquerqueFX,

    Thanks for your comment and advice!

    Kind regards,
    Jason.

    ReplyDelete
  5. Many thanks, I got here thanks to a Stack Overflow post: http://stackoverflow.com/questions/8605122/how-do-i-resolve-configuration-errors-with-nant-0-91/8605149#8605149

    ReplyDelete
  6. I know about the Unblock, I did it for all the other tools I had to install... bud just forgot one. Took me 2 hours to find out what wend wrong and what was causing the problems. Thanks MS, for the clear and clean information... not. :-)

    You got me going again, thanks!

    ReplyDelete
  7. Hi Andre,

    Glad the above helped you.

    Kind regards,
    Jason.

    ReplyDelete
  8. Thanks surfjungle for explaining this issue in details! This helps me fixed the problem~

    ReplyDelete
  9. that did really help !! Wasnt aware it was because of that.

    ReplyDelete
  10. Thank you it was really helpful

    ReplyDelete
  11. No problem - glad you found it useful : )

    ReplyDelete
  12. hi..Im student from Informatics engineering, this article is very informative, thanks for sharing :)

    ReplyDelete
  13. I have the same problem but my .zip file doesnt have Unblock button in properties. I am stuck. Please help

    ReplyDelete
  14. Thanks a lot . It really worked

    ReplyDelete
  15. Had the same issue on Windows 8.1. Thanks for your post!

    ReplyDelete