2008-06-18

How to make a self extracting exe for xcopy deployment

Often I think MSI is overkill when all i need to do, is copy some files to a production server.

So how to set up TFS Build Server to Create a exe from a zip file. (Note I use the http://msbuildtasks.tigris.org/ to create the initial zip file).

I found the free http://www.disoriented.com/FreeExtractor/ , you need to download the optional command line version.

(Note I have a Tools folder at the root of my solution)

At the top of the TFSBuild.proj add the following:

<UsingTask TaskName="MSBuild.Community.Tasks.Zip" AssemblyFile="$(SolutionRoot)\Tools\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll" /> 

Afterwards the folder can be zipped:

<CreateItem Include="$(DropLocation)\$(BuildNumber)\Release\**" >     <Output ItemName="ZipFiles" TaskParameter="Include"/>

  </CreateItem>

  <Zip ZipFileName="$(DropLocation)\$(BuildNumber)\deployment.zip" WorkingDirectory="$(DropLocation)\$(BuildNumber)" Files="@(ZipFiles)" /> 

And then use exec to call the MakeSFX:

<Exec Command="$(SolutionRoot)\Tools\FreeExtractor\MakeSFX.exe /nogui /zip=%22$(DropLocation)\$(BuildNumber)\deployment.zip%22 /sfx=%22$(DropLocation)\$(BuildNumber)\deployment.exe%22 /defaultpath=%22%24curdir%24%22 /exec=%22Deployment\AutoDeploy.bat%22 /autoextract /delete" IgnoreExitCode="true"  /> 

All you need to do is make make a bat file called AutoDeploy.bat, and do the xcopy operations from there.