Re: Using JScript.NET to implement a function

Mike Frederick <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nant.user
Message-ID <[email protected]>
Bob Archer wrote:
>> I am very familiar with JScript, but not with JScript.NET or C#.  I
>> want
>> to write a function in JScript.NET that I can use in my NAnt script.
>>
>> I currently have:
>>
>> <project name="TestFunction">
>>
>>     <target name="go"><echo>${script::testfunc()}</echo></target>
>>
>>     <script language="JS">
>>         <code>
>>         <![CDATA[
>>         public function testfunc():String { return ("Hello World from
>> JS"); }
>>         ]]>
>>         </code>
>>     </script>
>> </project>
>>
>> But when I run this I get:
>>
>> C:\hp\Scripts>nant -f:a.build go
>> NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
>> Copyright (C) 2001-2007 Gerry Shaw
>> http://nant.sourceforge.net
>>
>> Buildfile: file:///C:/hp/Scripts/a.build
>> Target framework: Microsoft .NET Framework 3.5
>> Target(s) specified: go
>>
>>    [script] Scanning assembly "l-qhzdpm" for extensions.
>>
>> go:
>>
>>
>> BUILD FAILED
>>
>> C:\hp\Scripts\a.build(4,4):
>> Unknown function 'script::testfunc'.
>> Expression: ${script::testfunc()}
>>     
>
> I'm not sure but you may have to annotate the function name:
>
> [Function("testfunc")]
>
> at the top of your script. 
>
> BOb
>
>
>   
Yes, that's what I thought.  When I add that line, I get:

C:\hp\Scripts>nant -f:a.build go
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/hp/Scripts/a.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: go


BUILD FAILED

C:\hp\Scripts\a.build(7,3):
Compilation failed:
C:\Documents and Settings\mike\Local Settings\Temp\oaw_xbfp.0.js(28,3) : 
error JS1002: Syntax error
//------------------------------------------------------------------------------
/// <autogenerated>
///     This code was generated by a tool.
///     Runtime Version: 2.0.50727.1433
///
///     Changes to this file may cause incorrect behavior and will be 
lost if
///     the code is regenerated.
/// </autogenerated>
//------------------------------------------------------------------------------

//@cc_on
//@set @debug(off)

import System;
import System.Collections;
import System.Collections.Specialized;
import System.IO;
import System.Text;
import System.Text.RegularExpressions;
import NAnt.Core;
import NAnt.Core.Attributes;


public FunctionSet("script", "script")
class nant7f8689ee26f04ddb9472f9b5a112bd8c extends 
NAnt.Core.FunctionSetBase {


  [Function("testfunc")]
  public function testfunc():String
  {
   return ("Hello World from JS");
  }


    public function nant7f8689ee26f04ddb9472f9b5a112bd8c(project : 
NAnt.Core.Project, propDict : NAnt.Core.PropertyDictionary) {
        super(project, propDict);
    }
}


Total time: 0.4 seconds.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.