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

 

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

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

image

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

image

打包好的模块:

image

转载于:https://www.cnblogs.com/DotNetNuke/archive/2009/08/27/1555422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的蚁群算法的 Matlab 代码实现。 ``` % 蚁群算法 % 目标函数为f(x)=x^2 % 求解[0,5]范围内的最小值 % 参数设置 nAnt = 20; % 蚂蚁数量 nIter = 100; % 迭代次数 alpha = 1; % 信息素重要程度因子 beta = 5; % 启发式因子 rho = 0.1; % 信息素挥发因子 Q = 1; % 常数因子 L = 5; % 信息素初始值 xMin = 0; % 搜索区间左端点 xMax = 5; % 搜索区间右端点 % 初始化 x = xMin + (xMax - xMin) * rand(1, nAnt); % 每只蚂蚁的位置 t = ones(1, nAnt) * L; % 每只蚂蚁所在位置的信息素 xBest = x(1); % 全局最优解 fBest = xBest^2; % 全局最优解对应的函数值 % 迭代 for iter = 1:nIter % 计算每只蚂蚁的概率分布 p = t.^alpha .* (1 ./ (x.^2 + eps)).^beta; p = p / sum(p); % 蚂蚁移动 xNew = zeros(1, nAnt); for k = 1:nAnt % 选择下一个位置 cumProb = cumsum(p); r = rand; j = find(cumProb >= r, 1, 'first'); xNew(k) = x(j); % 更新信息素 t(j) = (1 - rho) * t(j) + Q / (xNew(k)^2 + eps); % 更新全局最优解 fNew = xNew(k)^2; if fNew < fBest xBest = xNew(k); fBest = fNew; end end % 更新蚂蚁位置 x = xNew; end disp(['最优解为:', num2str(xBest)]); disp(['最优解对应的函数值为:', num2str(fBest)]); ``` 代码中的目标函数为 $f(x)=x^2$,在 $[0,5]$ 区间内寻找最小值。参数设置包括蚂蚁数量、迭代次数、信息素重要程度因子、启发式因子、信息素挥发因子、常数因子等。在迭代过程中,先计算每只蚂蚁的概率分布,然后根据概率分布选择下一个位置,更新信息素和全局最优解。最后输出最优解和最优解对应的函数值。 注意,该代码实现的是基本的蚁群算法,实际应用中可能需要根据具体问题进行改进和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值