Hi all,

One think I'd like to see implemented in Nant would be to have the Nant task
"inherit" properties defined by the invocation buildfile, in order to be
able to set properties in a master buildfile and have them be used when
building submodules through the NantTask.

Being a newbie in the Nant source, I "hacked" support for it by simply
modifying the code in NantTask to copy all properties from the current
task's Project into the new project's Property list. This seems to work just
fine in my tests, but I'm not quite sure what this might break down the
road. Basically, the problem is that since at that time the new project
hasn't initialized it's property list, you need to modify
PropertyDictionary.Add() so that it doesn't throw an exception a property
with the same name is added (which _will_ happen, since the new project now
has to "replace" some of the inherited properties, such as
nant.project.name).

So, imho, some refactoring would be needed in order to implement it in a
more appropriate manner. Perhaps separating the properties in those added by
nant itself (such as the nant.* and sys.* ones) and those added by the user
using -D: or the <property> task? I'm not sure.

Anyway, if anyone still cares for my hack, all that's needed it's three
things:

1- In PropertyDictionary.cs, modify Add() like this:
        public void Add(string name, string value) {
            if (!_readOnlyProperties.Contains(name)) {
               if ( Dictionary.Contains(name) )
                  Dictionary[name] = value;
               else
                  Dictionary.Add(name, value);
            }
        }
2- Add the following method to PropertyDictionary:
       public void CopyProperties(PropertyDictionary source) {
          Dictionary.Clear();
          foreach ( DictionaryEntry entry in source.Dictionary ) {
             if ( !Dictionary.Contains(entry.Key) ) {

                Dictionary[entry.Key] = entry.Value;
             }
          }
       }

3- In NantTask.cs, linie 81, add the following call:
               project.Properties.CopyProperties(this.Project.Properties);
Just before
                // handle multiple targets
                if (DefaultTarget != null) {


P.S. Since I'm pretty much a newbie when it comes to CVS, I couldn't find my
way around making a diff file...

--
 Tomas Restrepo
[EMAIL PROTECTED]


_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to