Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DotNetNuke ModulePackage.targets file that will package up your DNN module when built in release mode.
<?xml version="1.0" encoding="windows-1252"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Variable used to fine DNN Manifest File -->
<DNNFileName>$(AssemblyName)</DNNFileName>
<!--Variable used to create the install and source zip file-->
<PackageName>$(AssemblyName)</PackageName>
<!-- Variable used to find the location of the DotNetNuke installation bin folder. Used to get the projects binary DLL.
Assumes your your project will be stored in a company/module folder.
Ex: DesktopModules/CompanyName/ModuleName/-->
<MSBuildDnnBinPath Condition="'$(MSBuildDnnBinPath)' == ''">$(MSBuildProjectDirectory)\..\..\..\bin</MSBuildDnnBinPath>
</PropertyGroup>
<!-- Imports the community tasks for later use.
Used for: versioning, xml reading and writing. Compression. -->
<Import Project="MSBuild.Community.Tasks.Targets" />
<!-- Begins the main packaging of the project. This is called from the csproj -->
<Target Name="PackageModule" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<!--
Versioning of the module. Uses the version.txt file to store it's value. Every day from the StartDate that you build
the package in release mode it will add a new build version number. This allows you to create several builds in the same
day as the same version.
-->
<Version BuildType="Automatic" RevisionType="None" VersionFile="version.txt" StartDate="12/6/2012">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="Revision" />
</Version>
<!--
Write new version to assemblyinfo.cs. This will make sure that the DLL file is the same version as the manifest.
Keeping everything in sync
-->
<FileUpdate Files="Properties\AssemblyInfo.cs" Encoding="ASCII" Regex="AssemblyVersion\(&quot;.+&quot;\)" ReplacementText="AssemblyVersion(&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" />
<FileUpdate Files="Properties\AssemblyInfo.cs" Encoding="ASCII" Regex="AssemblyFileVersion\(&quot;.+&quot;\)" ReplacementText="AssemblyFileVersion(&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" />
<!--Adds the verion to the DNN manifest -->
<XmlUpdate Prefix="n"
Namespace="http://schemas.microsoft.com/developer/msbuild/2003"
XPath="dotnetnuke/packages/package[1]/@version"
XmlFileName="$(DNNFileName).dnn" Value="$(Major).$(Minor).$(Build).$(Revision)" />
<!-- Pulls the version back out from the DNN Manifest and stores it in a variable to be used later to attach to the package zips -->
<XmlRead Prefix="n"
Namespace="http://schemas.microsoft.com/developer/msbuild/2003"
XPath="dotnetnuke/packages/package[1]/@version"
XmlFileName="$(DNNFileName).dnn">
<Output TaskParameter="Value" PropertyName="Version" />
</XmlRead>
<!-- Search DNN Manifest for other Assemblies that need to be added to the package -->
<XmlRead Prefix="n"
Namespace="http://schemas.microsoft.com/developer/msbuild/2003"
XPath="dotnetnuke/packages/package/components/component/assemblies/assembly/name"
XmlFileName="$(DNNFileName).dnn">
<Output TaskParameter="Value" PropertyName="DLLS" />
</XmlRead>
<!--Assemblies above come out as a string. The need to be split in order loop through each DLL to add it to the zip. -->
<ItemGroup>
<SplitDLLs Include="$(DLLS.Split(';'))" />
</ItemGroup>
<!-- Files that will be added to the root of the package zips. These files are linked to in the DNN Manifest in order
to show during the Module installation. .HTM files are used to get the most features in the installation. -->
<ItemGroup>
<RootFiles Include="**\Documentation\License.htm" />
<RootFiles Include="**\Documentation\ReleaseNotes.htm" />
<RootFiles Include="**\*.sqldataprovider" />
<RootFiles Include="$(DNNFileName).dnn" />
</ItemGroup>
<!-- Files and folders that will be excluded from both packages. -->
<ItemGroup>
<DefaultExclude Include="**\.svn\**" />
<DefaultExclude Include="**\bin\**" />
<DefaultExclude Include="**\obj\**" />
<DefaultExclude Include="**\Release\**" />
<DefaultExclude Include="**\Debug\**" />
<DefaultExclude Include="**\Test\**" />
<DefaultExclude Include="**\TestResults\**" />
<DefaultExclude Include="**\doc\**" />
<DefaultExclude Include="**\www\**" />
<DefaultExclude Include="**\*.user" />
<DefaultExclude Include="**\*.suo" />
<DefaultExclude Include="**\*.zip" />
<DefaultExclude Include="**\*ReSharper.*\**" />
<DefaultExclude Include="**\Tests*\**" />
<DefaultExclude Include="**\*.dnn" />
</ItemGroup>
<!-- Files that will be added to the install package. Note the default exclude collection on each item.
NOTE: If any file is missing from the install package simply add the extension here -->
<ItemGroup>
<InstallInclude Include="**\*.ascx" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.asmx" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.css" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.html" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.htm" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.resx" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.aspx" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.js" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.xsl" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.xslt" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.xml" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\images\*.*" Exclude="@(DefaultExclude)" />
<InstallInclude Include="**\*.txt" Exclude="@(DefaultExclude);**\version.txt;" />
</ItemGroup>
<!-- FIles that will be added to the source package. Essentially everything but primary exclusion list. -->
<ItemGroup>
<SourceInclude Include="**\*.*" Exclude="@(DefaultExclude)" />
</ItemGroup>
<!-- Copy the files to be used for the INSTALL RESOURCES.ZIP file into a temp folder -->
<Copy SourceFiles="@(InstallInclude)" DestinationFolder="$(MSBuildProjectDirectory)\ResourcesZip\%(RecursiveDir)" />
<!-- Creates a variable of all the files found in the Resources.zip temp folder. -->
<CreateItem Include="$(MSBuildProjectDirectory)\ResourcesZip\**\*.*">
<Output TaskParameter="Include" ItemName="ResourcesContent" />
</CreateItem>
<!-- Creates the Resources.zip file -->
<Zip Files="@(ResourcesContent)" WorkingDirectory="$(MSBuildProjectDirectory)\ResourcesZip" ZipFileName="Resources.zip" />
<!-- Moves that Resources.zip to a package folder. -->
<Copy SourceFiles="$(MSBuildProjectDirectory)\Resources.zip" DestinationFolder="package/" />
<!-- Copies the DLLS needed for the package into the root directory. -->
<Copy SourceFiles="$(MSBuildDnnBinPath)\%(SplitDLLs.Filename)%(SplitDLLs.Extension)" DestinationFolder="$(MSBuildProjectDirectory)\Package\bin"/>
<!-- Copies the files that will be shown in the root of the zip package -->
<Copy SourceFiles="@(RootFiles)" DestinationFolder="$(MSBuildProjectDirectory)\Package" />
<!--Creates a variable of all the files in the package folder. This will be used to create the install package.-->
<CreateItem Include="$(MSBuildProjectDirectory)\Package\**\*.*">
<Output TaskParameter="Include" ItemName="OutputContent" />
</CreateItem>
<!-- Zipps all the files in the package folder and saves it as the INSTALL package. Appends the version number to the end of the file name.-->
<Zip Files="@(OutputContent)" WorkingDirectory="$(MSBuildProjectDirectory)\Package" ZipFileName="$(PackageName)_$(Version)_Install.zip" />
<!--Moves the INSTALL package zip to the packages folder. Install package is now complete. -->
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(PackageName)_$(Version)_Install.zip" DestinationFolder="packages/" />
<!-- Clean up Files. Remove the ResourcesZip and Package folder. Folders will be reused again for source package. -->
<RemoveDir Directories ="$(MSBuildProjectDirectory)\Package" />
<RemoveDir Directories ="$(MSBuildProjectDirectory)\ResourcesZip" />
<!-- create the SOURCE RESOURCES.ZIP file -->
<Copy SourceFiles="@(SourceInclude)" DestinationFolder="$(MSBuildProjectDirectory)\ResourcesZip\%(RecursiveDir)" />
<CreateItem Include="$(MSBuildProjectDirectory)\ResourcesZip\**\*.*">
<Output TaskParameter="Include" ItemName="SourceContent" />
</CreateItem>
<Zip Files="@(SourceContent)" WorkingDirectory="$(MSBuildProjectDirectory)\ResourcesZip" ZipFileName="Resources.zip" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\Resources.zip" DestinationFolder="package/" />
<!-- Create the Source package -->
<Copy SourceFiles="$(MSBuildDnnBinPath)\%(SplitDLLs.Filename)%(SplitDLLs.Extension)" DestinationFolder="$(MSBuildProjectDirectory)\Package\bin"/>
<Copy SourceFiles="@(RootFiles)" DestinationFolder="$(MSBuildProjectDirectory)\Package" />
<CreateItem Include="$(MSBuildProjectDirectory)\Package\**\*.*">
<Output TaskParameter="Include" ItemName="OutputSource" />
</CreateItem>
<Zip Files="@(OutputSource)" WorkingDirectory="$(MSBuildProjectDirectory)\Package" ZipFileName="$(PackageName)_$(Version)_Source.zip" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(PackageName)_$(Version)_Source.zip" DestinationFolder="packages/" />
<!-- Clean up Files -->
<RemoveDir Directories ="$(MSBuildProjectDirectory)\Package" />
<RemoveDir Directories ="$(MSBuildProjectDirectory)\ResourcesZip" />
<!-- General Clean Up-->
<Delete Files="$(MSBuildProjectDirectory)\$(PackageName)_$(Version)_Install.zip" />
<Delete Files="$(MSBuildProjectDirectory)\$(PackageName)_$(Version)_Source.zip" />
<Delete Files="$(MSBuildProjectDirectory)\Resources.Zip" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.