请首先浏览本文上一篇文章
《nant的典型应用——部署web站点》
windows服务与web站点的区别在于nant构建脚本略有不同,大体上还是分为获取源代码、编译类库、编译windows服务几个步骤,不同的是安装/反安装服务步骤。示例构建脚本如下:
<?xml version="1.0" encoding="utf-8" ?>
<!-- 项目名称,只用于显示 -->
<project name="project_name" >
<!-- 使用NAnt.Contrib,指定Contrib的路径 -->
<loadtasks assembly="C:/OneClickDeploy/nantcontrib-0.86/NAnt.Contrib.Tasks.dll" />
<!-- 源代码环境配置 -->
<!-- 源代码输出路径,默认为输出到当前文件夹下的src文件夹 -->
<property name="source.outdir" value="src"/>
<!-- svn服务器地址 -->
<property name="source.svn.path" value="svn://server/trunk/win_service0"/>
<!-- svn用户名 -->
<property name="source.svn.username" value="user"/>
<!-- svn密码 -->
<property name="source.svn.password" value="pass"/>
<!--
***************************************************************************
更新代码:如果代码已签出,执行update命令,否则执行checkout命令,一般不需要修改
***************************************************************************
-->
<target name="source">
<if test="${directory::exists(source.outdir)}">
<echo message="更新代码${source.svn.path}"/>
<svn-update uri="${source.svn.path}" destination="${source.outdir}" username="${source.svn.username}" password="${source.svn.password}" verbose="false" />
</if>
<if test="${not directory::exists(source.outdir)}">
<echo message="签出代码${source.svn.path}"/>
<mkdir dir="${source.outdir}"/>
<svn-checkout uri="${source.svn.path}" destination="${source.outdir}" username="${source.svn.username}" password="${source.svn.password}" verbose="false" cache-auth="false" />
</if>
</target>
<!--
编译代码“函数”
compile.target:exe, winexe, library or module
compile.assembly: 程序集
compile.outdir: 输出路径
complie.debug: true/false
-->
<target name="compile">
<!-- 生成编译后的文件名 -->
<if test="${compile.target=='library'}">
<property name="compile.output" value="${compile.assembly}.dll"/>
</if>
<if test="${compile.target=='winexe'}">
<property name="compile.output" value="${compile.assembly}.exe"/>
</if>
<csc target="${compile.target}" output="${path::combine(compile.outdir, compile.output)}" debug="${compile.debug}" optimize="true" verbose="false">
<sources>
<!-- 编译所有cs文件 -->
<include name="${source.outdir}/${compile.assembly}/**/*.cs" />
</sources>
<references>
<!-- 编译引用的dll文件,我将依赖的dll放到了svn://server/trunk/web0/Assembly文件夹下,所以这里需要制定引用Assembly下的所有dll文件 -->
<include name="${source.outdir}/Assembly/**/*.dll" />
<!-- 引用编译结果文件夹下的所有dll文件,一般来说类库项目之间也存在应用关系,基础类库编译完成后将编译结果dll存放compile.outdir文件夹下,编译业务类库时需要引用基础类库,因此需要引用compile.outdir下的所有dll -->
<include name="${compile.outdir}/**/*.dll" />
<!-- 排除引用的dll文件 -->
<exclude name="${source.outdir}/Assembly/**/libmySQL.dll"/>
</references>
<resources>
<!-- 嵌入的资源,需要将nhibernate映射文件作为嵌入的资源,编译到程序集中 -->
<include name="${source.outdir}/${compile.assembly}/**/*.hbm.xml" />
</resources>
</csc>
</target>
<!--
***************************************************************************
构建服务
***************************************************************************
compile.debug:
/debug [+/-] :当选用/debug +就会把创建.pdb文件,并把调试信息存储到里面;/debug -是一个缺省设置,就是不产生任何调试信息。
/debug:[full/pdbonly] :当使用/debug:full就是创建缺省的调试信息,有点类似/debug+选项。/debug: pdbonly选项是创建.pdb文件,并且你只能使用源代码调试在调试工具里。
compile.outdir:
编译结果输出文件夹
-->
<property name="compile.debug" value="PdbOnly"/>
<property name="compile.outdir" value="bin/sms"/>
<target name="compile-sms" description="编译服务">
<echo message="编译服务"/>
<delete dir="${compile.outdir}" verbose="true" if="${directory::exists(compile.outdir)}" />
<mkdir dir="${compile.outdir}"/>
<property name="compile.assembly" value="Common"/>
<property name="compile.target" value="library"/>
<call target="compile" />
<property name="compile.assembly" value="Business"/>
<property name="compile.target" value="library"/>
<call target="compile" />
<property name="compile.assembly" value="Sms"/>
<property name="compile.target" value="winexe"/>
<call target="compile" />
</target>
<!--
***************************************************************************
部署服务
***************************************************************************
-->
<!-- 服务名称 -->
<property name="service.name" value="WinServic"/>
<!-- 服务运行路径 -->
<property name="deploy.rundir" value="C:/WinServic"/>
<target name="deploy-service" description="部署服务">
<echo message="部署服务"/>
<property name="service.path" value="${deploy.rundir}/${service.name}.exe"/>
<!-- 卸载原服务 -->
<if test="${file::exists(service.path)}">
<exec program="installutil">
<arg value="${service.path}" />
<arg value="/u" />
<arg value="/LogFile" />
</exec>
</if>
<!-- 将编译结果复制到运行目录 -->
<delete dir="${deploy.rundir}" if="${directory::exists(deploy.rundir)}" />
<copy todir="${deploy.rundir}">
<fileset basedir="${compile.outdir}">
<include name="/**/*.*"/>
</fileset>
</copy>
<!-- 复制配置文件 -->
<copy todir="${deploy.rundir}">
<fileset basedir="${source.outdir}/Sms">
<include name="_config/**/*.*"/>
</fileset>
</copy>
<!-- 复制依赖类库 -->
<copy todir="${deploy.rundir}">
<fileset basedir="${source.outdir}/Assembly">
<include name="Antlr3.Runtime.dll" />
<include name="Iesi.Collections.dll" />
<include name="NHibernate.ByteCode.LinFu.dll" />
<include name="NHibernate.dll" />
<include name="LinFu.DynamicProxy.dll" />
<include name="ImApiDotNet.dll" />
<include name="libmySQL.dll" />
<include name="log4net.dll" />
<include name="Newtonsoft.Json.dll" />
</fileset>
</copy>
<!--安装服务-->
<exec program="installutil">
<arg value="${service.path}" />
<arg value="/LogFile" />
</exec>
</target>
<!--
***************************************************************************
启动服务
***************************************************************************
-->
<target name="run-service" description="启动服务">
<echo message="启动服务"/>
<!-- 启动服务 -->
<servicecontroller action="Start" service="${service.name}" verbose="true" />
</target>
</project>
使用
将上面的构建文件保存在任意文件夹下,如c:\deploy\service.build,并在这个文件夹下创建批处理脚本deploy-service.bat
path=C:\OneClickDeploy\nant-0.86;C:\OneClickDeploy\SlikSvn;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
nant -t:net-3.5 -buildfile:service.build source compile-service deploy-service run-service
pause
运行deploy-service.bat,首先会设置nant、svn、.net2.0 framework的路径,然后使用构建脚本进行部署:
1.更新源代码,首次运行会签出源代码
2.编译类库,示例中为Common、Business
3.编译服务代码
4.卸载原服务
5.将编译结果及依赖类库复制到运行目录
6.安装新服务
7.启动服务
分享到:
- 2009-09-27 17:31
- 浏览 937
- 评论(0)
- 论坛回复 / 浏览 (0 / 2251)
- 查看更多
相关推荐
使用NAnt进行每日构建 可自动从vstf下载和编译源码,并且自动部署站点
在java下有开源的ant,在asp.net下有Nant
NAnt配置过程,以及使用NAnt编译.NEt项目的一个简单示例。
新版本的nant,欢迎大家使用,这是二进制版本nant-0.91-alpha2-bin
学习NAnt小Demo_Build CS+Solution+MSBuild+SVN+NUnit+NUnitReport
.NET Framework 2.0和.NET Framework 3.5都可用。
遗憾的是,NAnt 缺少漂亮的图形界面,但它的确具有可以指定应该在生成过程中完成哪些任务的控制台应用程序和 XML 文件。注意,MSBuild(属于 Visual Studio 2010 的新的生成平台)为每种健壮的生成方案进行了准备,...
遗憾的是,NAnt 缺少漂亮的图形界面,但它的确具有可以指定应该在生成过程中完成哪些任务的控制台应用程序和 XML 文件。注意,MSBuild(属于 Visual Studio 2005 的新的生成平台)为每种健壮的生成方案进行了准备,...
本文讲述了配置EditPlus与NAnt构建轻型的.NET开发环境的步骤:首先是配置EditPlus;然后是配置一下C#的编译环境;然后就是配置NAnt;最后还可以写一个简单的批处理文件,让以后编译只需要 双击这个文件就可以了。...
遗憾的是,NAnt 缺少漂亮的图形界面,但它的确具有可以指定应该在生成过程中完成哪些任务的控制台应用程序和 XML 文件。注意,MSBuild(属于 Visual Studio 2005 的新的生成平台)为每种健壮的生成方案进行了准备,...
遗憾的是,NAnt 缺少漂亮的图形界面,但它的确具有可以指定应该在生成过程中完成哪些任务的控制台应用程序和 XML 文件。注意,MSBuild(属于 Visual Studio 2008 的新的生成平台)为每种健壮的生成方案进行了准备,...
使用protobuf编译proto为C#,再通过NAnt编译C#为dll,最后使用protobuf编译dll成为序列化dll的过程总结,包含详细的文档及相关说明和截图
nant 的可视化截面,可以让我门简单的使用nant
该软件包包含Windows Shell扩展,该扩展使用来自NAnt构建脚本( *.build )的目标来扩展Windows资源管理器的上下文菜单。 上下文菜单:- 列出项目目标并进行描述。 执行所选项目的目标。 编辑构建脚本 启动NAnt...
nant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-binnant-0.92-bin
nant-0.91-alpha1-bin.zip
集成CruiseControl.NET, NAnt, and NUnit一起工作。
使用Nant构建Xamarin.Android/Visual Studio应用程序
NAnt是一个类似于.NET的类似于Ant的构建工具
在.NET环境中实现每日构建--NAnt篇