If you want to create deployment zip packages for any Microsoft Visual Studio project type (like, Web Site, Web Service, Windows Service, Console Application etc. then just follow the steps below:
In this example I will be zipping all content files and *.dll files found in the "bin" folder of an ASP .NET MVC 4 Web Application, but the same will work for other project types. This example will be using the MSBuild Community Zip Task and at this point will work for .NET projects <= 4.5.
Create a new ASP .NET MVC 4 Web Application
In Microsoft Visual Studio 2012, choose:
File > New > Project…
Choose Internet Application
Add the nuget package"MSBuild Community Tasks"
Click click the solution in the Solution Explorer and choose "Manage NuGet Packages for Solution…"
Edit the MSBuild.Community.Tasks.targets file, so it will use the MSBuild.Community.Tasks.dll found in the .build folder created by the NuGet package.
Edit the *.csproj file
Unload project (right click project > Unload Project)
Edit *.csproj file
Scroll to the bottom of the file and
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> -->
<!-- Start Zip target --> <ItemGroup> <!-- Add all *.dll files found in the root of the "bin" folder as link files. - Use Files="@(Content);@(Link)" in the zip target the include both content files as build output in the zip content.
- Using the "@(Content);@(Link)" notation, will merge ItemGroup Content and ItemGroup Link into one property. - The ".\" before the "bin" folder name in the Include, results in a zip package containing the bin folder. - If you do not want to include the "bin" folder itself but only the files, use "bin\*.dll". - If you want to include subfolders use ".\bin\**\*.dll" --> <Link Include=".\bin\*.dll" />
<Link Include=".\bin\*.exe" />
<Link Include=".\bin\*.exe.config" /> </ItemGroup> <!-- A relative path will start from the *.csproj file location, so to get to the MSBuild.Community.Tasks.Targets file, we must add "..\.build\". --> <Import Project="..\.build\MSBuild.Community.Tasks.Targets" /> <!-- The afterbuild target will only be executed, when the project is build in "Release" mode. --> <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'"> <PropertyGroup> <ReleasePath>bin</ReleasePath> </PropertyGroup> <Zip Files="@(Content);@(Link)" WorkingDirectory="$(ReleasePath)" ZipFileName="output$(AssemblyName).zip" ZipLevel="9" /> </Target> <!-- End Zip target -->
Build project project in "Release" configuration
An output folder should be created containing the MVC1Application.zip.