MSBuild: Packaging (7 of 7)
November 30th, 2006When the projects has been built and tested it is helpful to place it into a single package to be deployed. For a website a zip file is sufficient. For another type of application a MSI installer is appropriate. Both packages will be covered here.
Creating a Zip File
Support for creating zip files is not a core task for MSBuild. Instead you must use the MSBuild Community Tasks, an open source project which has been producing tasks for MSBuild. One such task is the Zip Task. With this task you can place all of your outputs into a single zip file to make it easy to move to the Production environment where it is unzipped into the proper directories.
Below is a sample MSBuild script which creates a zip file.
At the very top a reference to the MSBuild Community Tasks is made to import the additional tasks. Then the Build target builds the Web Deployment Project which generates the files to the OutputDirectory. Finally the Package target creates the zip file using the CreateItem task which references all of the files in the OutputDirectory. And this sequence is enforced by using the DependsOnTarget attributes with Package requiring Build and Build requiring Clean.
Creating an MSI File
Building an MSI project is not supported by MSBuild either. The only way to build the Setup Projects which produce the MSI files is with Visual Studio. Fortunately there is a way this can be done from the command-line. Below is an MSBuild script which produces an MSI file using the Visual Studio command-line options.
This MSBuild script references Visual Studio 8 (aka Visual Studio 2005) directly in the VisualStudio8 property. In the BuildSetup target, the existence of the command is checked and the Exec task calls the command to build the Setup project. Once completed a new MSI file will be created in the output directory which is ready to be deployed for users to install the updated application.
More Information:
You should now be ready to build your own rich MSBuild scripts to build, test, and package your projects so they are ready for deployment. I hope this series has been helpful. Thanks for reading.

December 5th, 2007 at 4:00 pm
Hi,
I tried using the script from "Creating an MSI File" section. I wasn't able to successfully run the script. The error I'm getting is: The system cannot find the file specified. I tried eliminating tag by tag to narrow the search. Even the simplest pice of code within project tags generates the same error. Could you please advise what's missing?
Thank you.
December 5th, 2007 at 7:38 pm
Hi again,
I placed my script in batch file and ran it. It works fine, but doesn't produce the msi file. The script I'm using is the one I sent you earlier.
Here is the call:
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe" "C:\text_msi.bat"
Thank you.
Gayane