天天看點

Automated DotNetNuke Module Packaging MSBuild

原文轉自:http://www.dnnsoftware.com/wiki/Page/Automated-DotNetNuke-Module-Packaging-MSBuild

    You can easily auto package your modules by making a few changes to the vbproj (or CSPROJ for C#) file for your project. Packaging your module is really just zipping up the correct files. You can do this with MSBuild by using the MS Build Community Tasks extension. Download it and install it from https://github.com/loresoft/msbuildtasks/downloads . Once you have that installed its a simple case of editing the vbproj file. To do this in Visual Studio:

  • Right click the project name in Solution Explorer
  • Select Unload Project
  • Right click the greyed out project name in Solution Explorer again
  • Select the Edit option.

    You will now see the MSBuild file for your project.  All of the modules and providers in the DotNetNuke Core project have this modification.  To see this modification you will have to use the source code in the CodePlex source tree as the pacakges distributed in the Source package have this modification removed because it relies on the MSBuild Community tasks being installed and it also causes a security prompt the first time it loads the project.

    The example code below is for the HTML Module.  Since all modules need to be packaged it makes sense to have a generic packaging script and just pass variables to it.  If you look at the HTML Module vbproj file you will a property group section like this:

    <PropertyGroup>
    
    <Extension>zip<Extension>
    
    <DNNFileName>dnn_HTML</DNNFileName>
    
    <PackageName>HTML_Community</PackageName>
    
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\..\..\BuildScripts</MSBuildCommunityTasksPath>
    
    </PropertyGroup>      
  • The next line
    <Import Project="..\..\BuildScripts\ModulePackage.Targets" />      
    Imports the generic packaging script from the file ModulePackage.Targets.  The next line tells MSBuild to execute the packaging after the build is completed.
    <Target Name="AfterBuild" DependsOnTargets="DebugProject;PackageModule"></Target>      

    This line tells MSBuild to execute both the DebugProject and PackageModule tasks, DebugProject is actually in the vbproj file below but the PackageModule task is in the imported build file.  The DebugProject task simply copies files to the root website so you can debug.  The PackageModule task firstly Imports the MSBuild Commumity tasks so we can use the Zip task and the XmlRead task.  This task is only executed when in Release mode.

    Then I use XmlRead to read the version of the module out of the .dnn file. 

    <XmlRead Prefix="n"
    
    Namespace="http://schemas.microsoft.com/developer/msbuild/2003"
    
    XPath="dotnetnuke/packages/package/@version"
    
    XmlFileName="$(DNNFileName).dnn">
    
    <Output TaskParameter="Value" PropertyName="Version" />
    
    </XmlRead>
    
          

This is then used later to name the package correctly.

Note: If working with a package that contains multiple sub-packages change the xpath to be "dotnetnuke/packages/package 1/@version" which will use the FIRST version number for the package.

Next we find the files we need and copy them to a Package folder.  Note that at DNN Corp we use a standard way to arrange our modules so we can use the same script across the modules. Now that we have all the files in the package folder we use the Zip task to zip all the files up and then create an Install zip file.  Lastly we delete any copied or created folders.  The nice thing about doing it this way is you don't need to execute any external program to do your build, you simply switch to Release mode and hit build.  The install zip is then created and dropped into the Website/Install/Modules folder ready to install.

Examples»

Christoc's DotNetNuke Module Development TemplateFor examples on using MSBuild to package modules check out the 00.00.05 release of the module development templates found at http://christoctemplate.codeplex.com

MS Build for DotNetNuke module developmentThis extension forge project automates the task of creating DotNetNuke module PA and Source packs using MS Build. This MS Build tasks will generate DNN manifest files (.dnn files for DNN 5.x), it will process and generate version #'s, all file updates, release notes, clean up and much more. In addition to packaging, all .js and .css are minified before putting them in the Install pack, for optimal performance. The original .js and .css files remain untouched. MS Build for DotNetNuke module development

繼續閱讀