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


    系列文章:

    如何使用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会自动读取这个版本号,并生成对应的打包文件。

    image 

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

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

    image

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

    image

    打包好的模块:

    image

  • 相关阅读:
    springboot项目引入通用mapper(tk.mybatis.mapper)的时候一些可能会踩的坑
    Zookeeper和Dubbo基本配置和调用
    Zookeeper和Dubbo介绍
    Git的基础命令大全,拉取推送,分支,合并,冲突
    Maven内置tomcat
    Maven高级,依赖传递和解决冲突,版本锁定,提取统一版本号
    SpringMvc的自定义异常,交给SpringMvc管理
    IDEA创建MavenWeb项目慢,问题根除
    Docker安装指南
    Docker容器入门
  • 原文地址:https://www.cnblogs.com/DotNetNuke/p/1555422.html
Copyright © 2020-2023  润新知