- NAnt 0.85的下载URL(http://nant.sourceforge.net/ )
- 0.85版的nant加上NAnt.exe.config就能对应Framework 3.5
- Cmd>nant /t:net-3.5 /f:Simple.build
Simple.build
<?xml version="1.0"?> <project name="Simple" default="run"> <property name="debug" value="true"/> <target name="clean" description="remove all generated files"> <delete file="bin/Simple.exe" if="${file::exists('bin/Simple.exe')}" /> <delete file="bin/Simple.pdb" if="${file::exists('bin/Simple.pdb')}" /> </target> <target name="build" description="compiles the source code"> <mkdir dir="bin" /> <csc target="exe" output="bin/Simple.exe" debug="${debug}"> <sources> <include name="Program.cs" /> </sources> </csc> </target> <target name="run" depends="build"> <exec program="bin/Simple.exe" /> </target> </project>
Program.cs
using System.Data.SqlClient; using System; namespace DBSample { class Program { static void Main(string[] args) { string con = "user id=sa;password=password;server=tcp:127.0.0.1,4833;database=MY-DB;connection timeout=30"; SqlConnection myConnection = new SqlConnection(con); myConnection.Open(); SqlCommand myCommand = new SqlCommand("SELECT * FROM T_key", myConnection); SqlDataReader myReader = myCommand.ExecuteReader(); while (myReader.Read()) { Console.WriteLine(myReader["MyKey"].ToString()); Console.WriteLine(myReader["Name"].ToString()); } myConnection.Close(); Console.ReadLine(); } } }