0 Comments

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…

image

Choose Internet Application

image

 

Add the nuget package"MSBuild Community Tasks"

Click click the solution in the Solution Explorer and choose "Manage NuGet Packages for Solution…"

image

Choose MSBuildTasks

image

 

 

Edit MSBuild.Community.Tasks.targets

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.

image

 

Change:

<MSBuildCommunityTasksLib>$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll</MSBuildCommunityTasksLib>

To

<MSBuildCommunityTasksLib>MSBuild.Community.Tasks.dll</MSBuildCommunityTasksLib>

Result

image

 

 

Edit the *.csproj file

Unload project (right click project > Unload Project)

image

 

Edit *.csproj file

image

Scroll to the bottom of the file and

change:

<!-- 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> -->

 

To:

<!-- 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 -->

 

Reload project

image

 

Build project project in "Release" configuration

image

 

An output folder should be created containing the MVC1Application.zip.

image

 

Zip file:

image

Extracted

image

One Reply to “How to create deployment zip packages for any Microsoft Visual Studio 2012 project type, simply by editing the *.csproj files.

  1. Hi, I am very interested in getting this implemented. I followed your tutorial on a console application. But the zip file created doesn’t have any file.

    Can you assist?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts