如何使用NAnt 自动打包DNN模块 之二

简介: 系列文章: 如何使用NAnt 自动打包DNN模块 之一 如何使用NAnt 自动打包DNN模块 之二 使用MSBuilder编译项目时,会出现找不到引用的DLL的问题。可以参考这里解决:http://www.beefycode.com/post/Resolving-Binary-References-in-MSBuild.aspx 安装完NAnt之后,我们就可以使用NAnt自动打包模块了。

系列文章:

如何使用NAnt 自动打包DNN模块 之一

如何使用NAnt 自动打包DNN模块 之二

使用MSBuilder编译项目时,会出现找不到引用的DLL的问题。可以参考这里解决:http://www.beefycode.com/post/Resolving-Binary-References-in-MSBuild.aspx

安装完NAnt之后,我们就可以使用NAnt自动打包模块了。

跟使用NAnt完成其他任何一件任务一样,我们需要创建一个.build文件。大家可以下载我这个文件作为模板。

我们将使用MSBuilder来编译整个项目,使用NAnt把大部分文件压缩到一个Resource.zip文件,并最后制作出一个PA包和一个源代码包。

我们来仔细看看这个.builder文件,这是一个XML文件,root元素是一个project, 其中包含了若干个target元素,这些target元素就是关键了。这里我着重讲一下需要注意和根据需要修改的target元素,其它的部分大家可以自己看看,相信很容易理解。

先看看第一个:

初始化

<target name="init">
    <property name="nant.settings.currentframework" value="net-2.0" />
    
    <!-- .NET framework settings -->
    <property name="dotNetFrameworkVersion" value="v3.5" overwrite="false" />

    <!-- This is where your packaged zips will build to from within the module folder -->
    <property name="package.dir" value="package" overwrite="false" />

    <!-- This is where your resource.zip will be built so it can be zipped and distributed with the release install zips -->
    <property name="resourcezip.dir" value="ResourceZip" />
    <property name="bin.dir" value="http://www.cnblogs.com/bin" />
    <property name="controls.dir" value="controls" />
    <property name="localresource.dir" value="App_LocalResources" />
    <property name="globalresource.dir" value="App_GlobalResources" />

    <property name="binZip" value="_Install" />
    <property name="srcZip" value="_Source" />

    <property name="rootWeb" value="http://localhost/" overwrite="false" />
    <property name="webAlias" value="DNN483Source" overwrite="false" />
    <property name="verbose" value="true" overwrite="false" />

    <!-- ModuleName value should be set specific to the project -->
    <property name="CompanyName" value="AboutDNN" overwrite="false"/>
    <property name="ModuleName" value="FlashImageRotator"  overwrite="false"  />
    <property name="subproject.name" value="${CompanyName}_${ModuleName}"/>
    <property name="module.dll" value="${bin.dir}/${CompanyName}_${ModuleName}.dll" />

    <property name="debug" value="false" overwrite="false" />
    <property name="config" value="debug" if="${debug}" />
    <property name="config" value="release" unless="${debug}" />

    <sysinfo />

    <if test="${verbose}">
      <echo message="solutionName: ${subproject.name}" />
      <echo message="debug:        ${debug}" />
      <echo message="config:       ${config}" />
    </if>

  </target>
 

这节里面初始化了一些跟项目有关的信息,其中最重要的是CompayName和ModuleName了。需要修改为你们自己的名称,这里还有一点要注意的是,注意看那个"subproject.nam”和"module.dll”,是由CompanyName和ModuleName组合而成的,所以你的.sln文件和DLL名称一定要符合这个规定。比如我的CompayName是"AboutDNN”,ModuleName是"FlashImageRotator”,那么我的.sln文件和DLL文件名就是这样的:

AboutDNN_FlashImageRotator.sln

AboutDNN_FlashImageRotator.DLL 

定义如何为PA包制作Resource.zip 文件:

<!-- Begin area for creating resourcezip for installable PA zips (should depend on target that clears where this will build zip file to)-->
  <target name="CreateResourceZip" depends="CleanResourceZip">
    <!-- create a flat directory to zip for install -->
    <mkdir dir="temp" unless="${directory::exists('temp')}" />
    <!-- DO NOT flatten this as we want to retain folder structure in this and ONLY this zip -->
    <copy todir="temp" flatten="false">
      <fileset>
        <!-- Tell nant what files to grab -->
        <!-- everything included here ends up in resource.zip, this should be excluded in the CreateBinZip -->
        <include name="**/images/*" />
        <include name="**/Flash/*" />
        <include name="**/Resources/**/*" />
        <include name="**/Docs/*.pdf" />
        <include name="**/${localresource.dir}/*.resx" />
        <include name="**/${globalresource.dir}/*.resx" />
        <include name="**/${globalresource.dir}/*.xml" />
        <include name="**/*.ascx" />
        <include name="**/*.css" />
        <include name="**/*.aspx" />
        <exclude name="**/DNNDebug.aspx" />
        <exclude name="**/Resources.zip" />
        <exclude name="**/Install/**/*" />
        <exclude name="**/_sgbak/*" />
        <exclude name="**/thumbs.db" />
        <exclude name="**/*.zip" />
        <exclude name="**/docs/images/*" />

      </fileset>
    </copy>

    <mkdir dir="${resourcezip.dir}" unless="${directory::exists(resourcezip.dir)}" />
    <zip zipfile="${resourcezip.dir}/Resources.zip">
      <fileset basedir="temp">
        <include name="**/*" />
        <exclude name="**/*.dll" />

      </fileset>
    </zip>

    <!--Delete temp directory -->
    <delete dir="temp" failonerror="false" />

  </target>

修改fileset部分就可以定义那些文件会打包进PA安装包的

制作源代码包的zip文件

<target name="CreateResourceSourceZip" depends="CleanResourceZip">
    <!-- create a flat directory to zip for install -->
    <mkdir dir="temp" unless="${directory::exists('temp')}" />
    <!-- DO NOT flatten this as we want to retain folder structure in this and ONLY this zip -->
    <copy todir="temp" flatten="false">
      <fileset>
        <!-- Tell nant what files to grab -->
        <!-- everything included here ends up in resource.zip, this should be excluded in the CreateBinZip -->
        <include name="**/images/*" />
        <include name="**/Themes/**/*" />
        <include name="**/Resources/**/*" />
        <include name="**/Documentation/**" />
        <include name="**/${localresource.dir}/*.resx" />
        <include name="**/${globalresource.dir}/*.resx" />
        <include name="**/${globalresource.dir}/*.xml" />
        <include name="**/*.ascx" />
        <include name="**/*.aspx" />
        <include name="**/*.cs" />
        <include name="**/*.sln" />
        <include name="**/*.csproj" />
        <include name="**/*.build" />
        <exclude name="**/DNNDebug.aspx" />
        <exclude name="**/Install/**/*" />
        <exclude name="**/_sgbak/*" />
        <exclude name="**/thumbs.db" />
        <exclude name="**/*.zip" />
        <exclude name="**/04.03.02.txt" />

      </fileset>
    </copy>

    <mkdir dir="${resourcezip.dir}" unless="${directory::exists(resourcezip.dir)}" />
    <zip zipfile="${resourcezip.dir}/Resources.zip">
      <fileset basedir="temp">
        <include name="**/*" />
        <exclude name="**/*.dll" />

      </fileset>
    </zip>

    <!--Delete temp directory -->
    <delete dir="temp" failonerror="false" />

  </target>

设置版本号

最后我们要保证在AssemblyInfo.cs文件中,正确的设置了一个版本号,这样NAnt会自动读取这个版本号,并生成对应的打包文件。

 

到这里,就修改完.builder文件了。其实对于大家来说,只需要修改初始化部分的公司名称和项目名称就可以了,其它部分都可以使用默认的设置。

最后我们来让NAnt帮我们打包模块,进入到你模块所在的目录,键入NAnt命令:

image

NAnt之后就会卖力的编译模块和打包,哈,25秒搞定:

image

打包好的模块:

image

目录
相关文章
|
6月前
|
缓存 Java Maven
深入理解Gradle构建系统的工作原理
深入理解Gradle构建系统的工作原理
165 0
|
程序员 Android开发 开发者
Android开发:往项目工程里面新引入工具包的步骤
在Android开发过程中,有些时候会根据实际需要,要往项目里面引入工具包,作为初级开发者或者刚开始入门的Android开发者来说会不太熟练怎么引入,所以往项目工程里面新引入工具包也是必备技能。那么本篇博文就来分享一下给项目工程里面引入工具包的步骤,只分享给有需要的人。
163 0
Android开发:往项目工程里面新引入工具包的步骤
|
前端开发 JavaScript
精读《如何编译前端项目与组件》
# 1 引言 说到前端编译方案,也就是如何打包项目,如何编译组件,可选方案有很多,比如: - 通过 webpack / parcel / gulp 构建项目。 - 通过 parcel / gulp / babel 构建组件。 如果你喜欢零配置的 parcel,那么项目和组件都可以拿它来编译。 如果你业务比较复杂,需要使用 webpack 做深度定制,那么常见组合是:项目
1040 0
|
Shell 开发工具 Windows
Nuget 多平台多目标快速自动打包
构建现代的 .Net 应用离不开 Nuget 的支持,而快速打包 Nuget 成了提高生产率的有效方法。 1. 前置条件 为了实现 Nuget 的快速打包,我们需要先解决一些前置依赖,无论是 .Net Framework、Mono 或者 .Net Standard(.Net Core),我们都需要先编译通过,然后再打包成 Nuget 包,最后再发布到 Nuget 服务器上。
1617 0
|
API 算法框架/工具 Python
TensorFlow固化模型+打包程序+web API
固化Tensorflow模型,使用flask搭建简易web API,打包python代码
6492 0
|
IDE 开发工具 C语言
xmake入门,构建项目原来可以如此简单
前言 在开发xmake之前,我一直在使用gnumake/makefile来维护个人C/C++项目,一开始还好,然而等项目越来越庞大后,维护起来就非常吃力了,后续也用过一阵子automake系列工具,并不是很好用。
1470 0
|
Java API Android开发
Gradle2.0用户指南翻译——第十三章. 编写构建脚本
翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2.0 。
1418 0
|
XML Java Android开发
由模型生成GEF应用程序:Merlin
接触和使用过EMF的朋友都知道,只要定义好ecore模型,就能够利用EMF的代码生成工具得到一个可用编辑器,而ecore模型可以从rose模型、java接口或xml schema很方便的转换生成。不过,虽然得到的编辑器从功能上来说是足够了,但针对不同的需求还须要进行定制,这里的工作并不少,如果想定制为图形化编辑器要改的就更多了,基本上相当于重写的工作量。
1335 0
|
存储 监控
NAnt 简介
表达式是一种简单而强大的机制,允许写高级的公式,用于 task 的参数和条件式中,这样就可以控制连编过程了。表达式能够访问 project 的属性、调用内建的或者用户定义的functions 。
1592 0