如何使用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月前
|
机器学习/深度学习 算法 PyTorch
OpenCV-图像着色(采用DNN模块导入深度学习模型)
OpenCV-图像着色(采用DNN模块导入深度学习模型)
来自OpenCv的DNN模块助力图像分类任务
来自OpenCv的DNN模块助力图像分类任务
133 0
来自OpenCv的DNN模块助力图像分类任务
|
机器学习/深度学习
DNN中如何一次性插入多个模块
需求 有时候,我们要用几个模块才能实现某一组功能,比如Blog模块,我们需要一个模块用列表显示Blog条目,需要一个模块显示Blog内容,需要一个模块显示历史Blog发帖记录,需要一个模块显示搜索,所有这些模块要在同一页面上同时显示,所以也不能用控件(Control)实现,并且我们想要这些模块...
678 0
|
机器学习/深度学习 数据格式 XML
模块DNN文件的版本记录和resource文件
做个笔记,就不详细讲了:  对模块的DNN XML 文件,有两个节点,一个是 ^[0-9]{1}[4-9]{1}.[0-9]{1}[6-9]{1}.[0-9]{1}[0-9]{1}$   这里可以用正则表达式指定模块兼容的版本,具体请参考:Minimum DotNetNuke Core Version Support 一个是: DNN_Announcements.
555 0
|
机器学习/深度学习
DNN永日新闻模块(YongRi)免费1.00.09版本下载
DNN上实现新闻发布国内模块很少,主要是使用永日新闻模块实现。最近不少人在寻找之前免费的1.00.09版本,为方便大家学习,我把这个模块传上来了。 下载链接:永日新闻模块1.00.09免费版本下载 此版本不支持图片新闻模板。
730 0
|
机器学习/深度学习
永日模块01.00.09不兼容DNN 4.3.7
近日发现永日01.00.09版本不兼容DNN 4.3.7, 表现是安装上去之后 show模块在管理员权限下正常现示但在普通权限下不能显示 show模块的“设置(Settings)”菜单不能显示永日自己的设置部份,这样也就无法给show模块指定显示"manager"模块里面那一部份的内容了 01.00.09在DNN 4.3.4下工作正常。
676 0
|
机器学习/深度学习
DNN4.3.3的版本开发的模块.没登陆DNN的情况下,按钮的事件有时候执行,有时候怎么点都不执行
Q:想问一下,我用DNN4.3.3的版本开发的模块. 为什么我在没登陆DNN的情况下,按钮的事件有时候执行,有时候怎么点都不执行啊. A:清空一下Cache就会正常
530 0
|
机器学习/深度学习 数据库 SQL
|
机器学习/深度学习
DNN 模块MVP 模式学习中的一些问题
为了让View部分可以测试,我们使用interface来分离View和业务逻辑的耦合。 我的问题是: Q:对于在aspx.design.cs中声明的控件,我们也需要在interface中声明吗?如果要声明,那么在aspx.design.cs中的控件声明是不是就是interface的实现? 我们不能在interface直接声明跟aspx.design.cs控件同名的变量,我们应该认为aspx.design.cs中的控件就是view的一部分,我们无法控制。
478 0
|
机器学习/深度学习 前端开发
介绍一些免费的DNN模块
网址:http://oliverhine.com/DotNetNuke.aspx Administration Advanced Control Panel Free fully featured ajax enabled control panel replacement for Dot...
820 0