> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:nant-users-
> [EMAIL PROTECTED] On Behalf Of Swiss Steve
> Sent: dinsdag 6 februari 2007 17:10
> To: nant-users@lists.sourceforge.net
> Subject: [NAnt-users] Returning Values from a Custom Nant Task
> 
> 
> I have written a simple NAnt custom task which I want to create
> property than
> can then be used in my NAnt scripts.   My problem is I dont know how to
> access this property from my scripts.   I have called the task so that
> it
> populated its internal variables and then tried the following to access
> the
> properties from my script
> 
> <echo message=${timestamp.basetimestamp}/>
> 
> Here is my custom task
> 
> namespace NAntTimeStamp
> {
>     [TaskName("timestamp")]
>     public class NAntTimeStampTask : Task
>     {
>         private string t = null;
>         private string tFile = null;
>         private string post = null;
>         private string pre = null;
> 
>         public void TestTask()
>         {
>            ExecuteTask();
>         }
> 
>         [TaskAttribute("basetimestamp", Required = false)]
>         [StringValidator(AllowEmpty = true)]
>         public string timeStamp
>         {
>             get { return t; }
>             set { t = value; }
>         }
> 
>         [TaskAttribute("filetimestamp", Required = false)]
>         [StringValidator(AllowEmpty = true)]
>         public string fileTimeStamp
>         {
>             get { return tFile; }
>             set { tFile = value; }
>         }
> 
>         [StringValidator(AllowEmpty = true)]
>         public string postFix
>         {
>             get { return post; }
>             set { post = value; }
>         }
> 
>         [TaskAttribute("prefix", Required = false)]
>         [StringValidator(AllowEmpty = true)]
>         public string preFix
>         {
>             get { return pre; }
>             set { pre = value; }
>         }
> 
>         protected override void ExecuteTask()
>         {
>             DateTime now = DateTime.Now;
>             string current = now.ToString();
>             tFile = current;
>             StringBuilder  buffer = new StringBuilder();
> 
>             buffer.Append("v1.");
>             buffer.Append(String.Format("{0:MM}",
> now.Month.ToString()));
>             buffer.Append(".");
>             buffer.Append(String.Format("{0:dd}", now.Day.ToString()));
>             buffer.Append(".");
>             buffer.Append(String.Format("{0:hh}",
> now.Hour.ToString()));
>             buffer.Append(String.Format("{0:mm}",
> now.Minute.ToString()));
>             buffer.Append(String.Format("{0:ss}",
> now.Second.ToString()));
> 
>             t = preFix + buffer + postFix;
>         }
> 
>     }
> }

You actually have to add the property (in ExecuteTask).

Eg.

Properties["timestamp.basetimestamp"] = t;

Gert


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to