- 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();
}
}
}
本文介绍如何使用NAnt 0.85版本配合NAnt.exe.config文件支持.NET Framework 3.5,并通过一个示例项目演示了源代码编译及执行过程。示例中还展示了如何利用C#连接SQL Server数据库并读取数据。
229

被折叠的 条评论
为什么被折叠?



