(nant入门)Framework 3.5 对应

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 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();
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值