In my last Blogpost I talked about howto integrate tests into the Buildscript. Today I´m going to write down an easy way how to zipp the build automatical.
You will find the magic trick in the MSBuildCommunity Tasks project.
Szenario
I just continued the solution from my last blogpost and by the way I downloaded the latest version of MSBuild Community Tasks.
As a side note: The MSI installer doesn´t work so I downloaded Zip with source. These files are from interest:
The following reference should be included into the MSBuild Script:
<Import Project="$(MSBuildStartupDirectory)\Lib\MSBuild.Community.Tasks.Targets"/>
Zipping or the problem with the documentation
The MSBuildCommunity Task Project is really huge but in my eyes it´s kind of undocumented. With the help of this post I found out how to open the ZipTasks.
Here you can see my entire MSBuild Script. Take a look at the target "zip"
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> <Import Project="$(MSBuildStartupDirectory)\Lib\MSBuild.Community.Tasks.Targets"/> <PropertyGroup> <OutDir>$(MSBuildStartupDirectory)\OutDir\</OutDir> <SolutionProperties> OutDir=$(OutDir); Platform=Any CPU; Configuration=Release </SolutionProperties> </PropertyGroup> <ItemGroup> <Solution Include="..\MsBuildSample.sln"> <Properties> $(SolutionProperties) </Properties> </Solution> </ItemGroup> <Target Name="Build"> <MSBuild Projects="@(Solution)"/> </Target> <Target Name="RunTests"> <Exec Command='"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /testcontainer:"$(MSBuildStartupDirectory)\OutDir\MsBuildSample.WebApp.Tests.dll" /testcontainer:"$(MSBuildStartupDirectory)\OutDir\AnotherTestProject.dll"' /> </Target> <ItemGroup> <!-- All files from build --> <ZipFiles Include="$(OutDir)_PublishedWebsites\**\*.*" /> </ItemGroup> <Target Name="Zip"> <Zip Files="@(ZipFiles)" WorkingDirectory="$(OutDir)_PublishedWebsites\" ZipFileName="$(OutDir)Package.zip"/> </Target> </Project>
The item "ZipFiles" includes all websites in my "OutDir". In the zip target I zipp all the files and deside from which folder they should be zipped. Last but not least: enter a name.
The call workes the same way like in my last posts with a .bat file:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe Buildsolution.targets /t:Build,RunTests,Zip
Thats the easy but effective way to create a kind of "deployment-package". Even if there is a lot of more stuff you can make with the help of Msdeploy, never say no to a little zip. ;)