Use conditional build events to freshen zip files in Visual Studio
I wanted to update a couple zip files of the VB version of my Blog Crawler (to be posted soon) with the latest and greatest when I built the Release version of a project. I used the XCOPY command with the /D option to update only if changed. Copying to a ZIP file extension actually puts the file into the ZIP file. Is this a feature of Win XP or Winzip? I suspect it’s Win XP Compressed folder behavior. Nice.
In VS 2005 (the steps for prior VS versions are slightly different), choose Project->Properties->Compile. Build Events.
I didn’t see a way to make the build events run conditionally depending on configuration: Debug or Release, nor did these configurations have their own separate settings. So, I used the IF command.
For the Post-Build Event, I added these lines using the build event editor and the Macros dialog to help build the strings.
if $(ConfigurationName)==Release xcopy /df $(ProjectDir)$(TargetName)*.vb $(ProjectDir)$(TargetName)Source.zip
if $(ConfigurationName)==Release xcopy /df $(TargetDir)$(TargetName)$(TargetExt) $(ProjectDir)$(TargetName)Runtime.zip
Choose: “Run the post build event:“ On Successful Build
In the Output Build window, the commands are echoed with the macros expanded, and the results are shown:
BlogCrawl -> d:\dev\vb\BlogCrawl\bin\Release\BlogCrawl.exe
if Release==Release xcopy /df d:\dev\vb\BlogCrawl\BlogCrawl*.vb d:\dev\vb\BlogCrawl\BlogCrawlSource.zip
if Release==Release xcopy /df d:\dev\vb\BlogCrawl\bin\Release\BlogCrawl.exe d:\dev\vb\BlogCrawl\BlogCrawlRuntime.zip
D:\dev\vb\BlogCrawl\BlogCrawl.vb -> D:\dev\vb\BlogCrawl\BlogCrawlSource.zip
1 File(s) copied
D:\dev\vb\BlogCrawl\bin\Release\BlogCrawl.exe -> D:\dev\vb\BlogCrawl\BlogCrawlRuntime.zip
1 File(s) copied
Of course, when building the Debug version the output is different:
BlogCrawl -> d:\dev\vb\BlogCrawl\bin\Debug\BlogCrawl.exe
if Debug==Release xcopy /df d:\dev\vb\BlogCrawl\BlogCrawl*.vb d:\dev\vb\BlogCrawl\BlogCrawlSource.zip
if Debug==Release xcopy /df d:\dev\vb\BlogCrawl\bin\Debug\BlogCrawl.exe d:\dev\vb\BlogCrawl\BlogCrawlRuntime.zip