Click here to Skip to main content
Licence GPL3
First Posted 3 Aug 2006
Views 57,601
Downloads 183
Bookmarked 35 times

The NAR loader - single file .NET deployment

By | 27 Oct 2006 | Article
JAR archives for .NET = NAR archives.

Sample application inside NAR archive

Introduction

Maybe, some of you know the concept of JAR archives from Java. A lot of things from Java have found their way to the .NET world. Having the same functionality for .NET would be a nice feature. Since .NET 2, Microsoft has included some very interesting features in the CLR and the framework. These features make it possible to create the functionality needed to handle archives for .NET - called NAR archives. NAR archives are ordinary ZIP files containing an (optional) XML manifest file - which informs the loader about what to load, and all application contents like the app.config file and the assemblies. The loader for these archives works only with .NET 2.x. .NET 1.x is not supported.

So today, we have XCOPY deployment of .NET applications, but tomorrow, we might have single file copy deployment for .NET applications.

Background

The CLR as the heart of .NET is a standard Windows component, and as such, it can be used by other (unmanaged) Windows applications to extend them with .NET functionality. This is also true for .NET 1.x. But since .NET 2.0, you can customize a lot more things when using the CLR. From telling the CLR from where to load assemblies (that's one thing that's used by the NAR loader), to how the GC should behave, or what to do with policies. By hosting the CLR in an application, you can extend it, but unfortunately, the way to achieve this is not always as straightforward as it could be. Especially, security can be tricky. The loader creates its own CAS group during installation. You can examine this group with the Microsoft .NET Framework 2.0 Configuration Control Panel applet (Control Panel/Administrative Tools/Microsoft .NET Framework 2.0 Configuration).

Using the code

The NAR loader consists of three parts:

  1. The unmanaged VC++ host for the CLR.

    The host is responsible for preparing the right conditions for the following managed part. It ensures that security is in place, configures the CLR, provides the assemblies of the NAR archive to the CLR, and after the application inside the NAR archives terminates, cleans up everything. This part also registers the file extension .nar with the NAR loader so that a double-click is enough to start applications from inside NAR archives.

  2. The managed C# domain manager.

    The assembly of the managed domain manager is included as a resource in the unmanaged host part of the loader. After the unmanaged part has finished initialization and setup, the assembly is extracted from the resource and loaded into the CLR. This is done in memory without extracting it to the disk first!

  3. A sample NAR archive with a test application which tests most aspects of .NET applications like satellite assemblies, private search paths, multi module assemblies etc.

    You will find Debug and Release builds zipped in the bin directory. Building the loader from source builds all three parts. A build should normally work without problems, but if it fails, it's likely that one of the custom build steps needs customization (Projects: NARTestModule, NARTest, NARLoaderManager, NARLoaderMain, and the file NARLoader.h in NARLoaderMain).

New features

This version of the loader is now capable of creating self running archives, including the possibility to use custom icons for the resulting .exe file. Now, you can pack your application's assemblies into one single .exe file and deploy this. Password protected, strong AES encrypted archives are now also possible. Use this feature to either obfuscate your applications assemblies and/or to control application usage.

If your archive contains a zip comment this can be displayed at application startup. It can be used to display license agreements or other information.

Points of interest

Hosting the CLR is a great way to extend unmanaged applications, but it is also an opportunity to extend the .NET environment itself. Using the CLR hosting interfaces is (most of the time) straightforward, but sometimes the available documentation on MSDN lacks some clarifying hints. During development, fuslogvw.exe was a valuable tool for debugging. By using NAR archives, application deployment can be simplified.

A full manual and further information about the NAR loader can be found at the NAR loader project website.

History

The latest stable version is 1.2 as of 26 October 2006.

Current version

1.2 2006.10.26 Adds support for strong AES encrypted, password protected archives and archive comments

Older versions

1.1 2006.08.17 Adds support for self-running archives including custom icons
1.0a 2006.08.03 Allows install and uninstall of loader CAS code group, and .nar file extension handling.
1.0 2005.03.03 First public release - no longer available

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Richard Prinz

Architect

Austria Austria

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalhost in c# PinmemberUnruled Boy16:41 7 Jan '09  
GeneralGreat idea PinmemberAlexander Stojakovic7:04 12 Feb '07  
GeneralCOM PinmemberBill Seddon22:47 25 Jan '07  
GeneralRe: COM PinmemberRichard Prinz22:55 26 Jan '07  
GeneralRe: COM PinmemberBill Seddon23:45 26 Jan '07  
GeneralRe: COM PinmemberRichard Prinz4:41 30 Jan '07  
GeneralRe: COM PinmemberBill Seddon5:09 30 Jan '07  
GeneralILMerge Pinmemberreinux16:03 27 Oct '06  
GeneralCannot load class by reflection PinmemberBarry Kwok15:29 21 Aug '06  
GeneralRe: Cannot load class by reflection PinmemberRichard Prinz23:10 21 Aug '06  
GeneralRe: Cannot load class by reflection PinmemberBarry Kwok15:46 22 Aug '06  
GeneralRe: Cannot load class by reflection PinmemberRichard Prinz19:38 22 Aug '06  
GeneralGreat Help at the right time! PinmemberThomas Krojer3:21 18 Aug '06  
QuestionDoesn't NetZ already do this? PinprotectorMarc Clifton16:21 7 Aug '06  
And all in managed code?
 
Marc
 

XPressTier

Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer


AnswerRe: Doesn't NetZ already do this? PinmemberHerman Chelette3:08 8 Aug '06  
GeneralRe: Doesn't NetZ already do this? PinmemberRichard Prinz3:56 9 Aug '06  
GeneralRe: Doesn't NetZ already do this? PinmemberHerman Chelette4:06 9 Aug '06  
GeneralNice. Pinmemberkjquinn4:22 4 Aug '06  
GeneralRe: Nice. PinmemberRichard Prinz6:27 4 Aug '06  
GeneralNice idea but.. PinmemberFZelle2:54 4 Aug '06  
GeneralRe: Nice idea but.. PinmemberRichard Prinz6:25 4 Aug '06  
GeneralRe: Nice idea but.. PinmemberFZelle8:19 4 Aug '06  
GeneralRe: Nice idea but.. PinmemberRichard Prinz9:36 4 Aug '06  
GeneralRe: Nice idea but.. PinmemberFZelle9:42 4 Aug '06  
GeneralNice Pinmember2ASoft14:11 3 Aug '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 27 Oct 2006
Article Copyright 2006 by Richard Prinz
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid