Actually custom functions and tasks are two different things. To start writing a custom task you might want to look at this article:
http://www.theserverside.net/articles/showarticle.tss?id=NAnt
as well as the sample in the nant sources \nant\examples\UserTask\UserTask.cs.
As to why you're getting that error - the script task doesn't currently process the asis attribute properly ( its a bug ). I need to migrate some logic from the compiler tasks to use the framework resolution stuff to resolve system assembly references.
try using the following for now:
<includes name="C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> and it should work. I get the following on my machine:
Function call failed.System.Data.Odbc.OdbcExceptionSystem.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
at NAnt.Core.ExpressionEvaluator.EvaluateFunction(String functionName, Object[] args) in h:\cvs\nant\src\NAnt.Core\ExpressionEv
aluator.cs:line 91
at NAnt.Core.ExpressionEvalBase.ParseValue() in h:\cvs\nant\src\NAnt.Core\ExpressionEvalBase.cs:line 595
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Ian
John Cole wrote:
Hello, First, thanks to everyone who helped get last nights CVS version to build, I was able to get both NAnt and NAntContrib built this morning.
I need to pull some info out of a MySQL database, and I'd like to use ODBC for this. The SQL task in NAntContrib will only use oledb datasources, and the only one I found for MySQL is incomplete and does not work, so I'm attempting to create my own taks for running an ODBC query. The task is as follows:
-----------------------------------------------
<target name="initsql">
<script language="C#" prefix="odbc">
<references>
<includes name="System.Data.dll" asis="true"/>
</references>
<code><![CDATA[
[Function("query")]
public static string Query(string pConnStr, string pSQL, string
pDelimiter) {
string s = "";
System.Data.Odbc.OdbcConnection c = new
System.Data.Odbc.OdbcConnection(pConnStr);
System.Data.Odbc.OdbcCommand cmd = new
System.Data.Odbc.OdbcCommand(pSQL, c);
c.Open();
System.Data.Odbc.OdbcDataReader r;
r = cmd.ExecuteReader();
while (r.Read()) {
string line = "";
for(int i = 0; i<r.FieldCount; i++)
{
if (line.Length > 0) line += pDelimiter;
line += r.GetString(i);
}
s += line + "\n";
}
r.Close();
c.Close();
return s;
}
]]></code>
</script>
<echo message="${odbc::query('DSN=mantis', 'select id, name, engine FROM
custom_report', ', ')}" />
</target>
-------------------------------------------------------
This code runs from Visual Stuido, but I get the following error when I attempt to run this from within NAnt:
------------------------------------------------------- NAnt 0.85 (Build 0.85.1594.0; net-1.1.win32; nightly; 5/13/2004) Copyright (C) 2001-2004 Gerry Shaw NAnt Team
Buildfile: file:///C:/Documents <file:///C:/Documents> and
Settings/jcole/My Documents/src/UtilityCenter/default.build
Target(s) specified: initsql
initsql:
BUILD FAILED
C:\Documents and Settings\jcole\My Documents\src\UtilityCenter\default.build(357,4): Compilation failed: c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(21,13) : error CS0234: The type or namespace name 'Data' does not exist in the class or namespace 'System' (are you missing an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(22,13) : error CS0234: The type or namespace name 'Data' does not exist in the class or namespace 'System' (are you missing an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(23,6) : error CS0246: The type or namespace name 'c' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(24,13) : error CS0234: The type or namespace name 'Data' does not exist in the class or namespace 'System' (are you missing an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(25,6) : error CS0103: The name 'r' does not exist in the class or namespace 'nant1fce0aafadd14e78ac9662d5dda7042c' c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(27,13) : error CS0246: The type or namespace name 'r' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(30,24) : error CS0246: The type or namespace name 'r' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(33,16) : error CS0246: The type or namespace name 'r' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(37,6) : error CS0246: The type or namespace name 'r' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\jcole\Local Settings\Temp\otnp2wzj.0.cs(38,6) : error CS0246: The type or namespace name 'c' could not be found (are you missing a using directive or an assembly reference?) -------------------------------------------------------
I've tried using the <references> and <includes> tags, but I haven't found the right combonation. How can I get a script to get access to System.Data.Odbc?
Thanks,
John Cole
------------------------------------- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
--
Ian MacLean, Developer, ActiveState, a division of Sophos
http://www.ActiveState.com
------------------------------------------------------- This SF.Net email is sponsored by: SourceForge.net Broadband Sign-up now for SourceForge Broadband and get the fastest 6.0/768 connection for only $19.95/mo for the first 3 months! http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click _______________________________________________ nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers