Sample code for 30+ languages & platforms
Xojo Plugin

ZIP a Visual Studio Project and Exclude Build Artifacts

See more Zip Examples

This example demonstrates how to create a ZIP archive of a Visual Studio project directory while excluding files and directories commonly created during builds.

This is useful when archiving or sharing source code without including compiled binaries, intermediate build output, debug symbols, cache files, or generated package folders.

The example excludes common Visual Studio build artifacts such as:

  • bin directories
  • obj directories
  • .vs directories
  • *.exe, *.dll, *.pdb, and related output files
  • Temporary and cache files

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

Dim zip As New Chilkat.Zip

// Create a new, empty Zip object.
// The .zip file is not created until WriteZip or WriteZipAndClose is called.
success = zip.NewZip("VisualStudioProject.zip")
If (success = False) Then
    System.DebugLog(zip.LastErrorText)
    Return
End If

// When the ZIP is extracted, all files will be placed beneath
// the "MyProject/" directory.
// 
// For example:
// 
//     src/main.cpp
// 
// Will be stored in the ZIP as:
// 
//     MyProject/src/main.cpp
// 
zip.PathPrefix = "MyProject/"

// We will add files from this Visual Studio project directory:
// 
//     c:/projects/MyProject
// 
// The goal is to ZIP the source project without the files generated
// by Visual Studio builds.

// ------------------------------------------------------------
// Exclude directories commonly created by Visual Studio builds.
// 
// Any directory having one of these names will be skipped entirely,
// including all files and subdirectories beneath it.
zip.ExcludeDir "bin"
zip.ExcludeDir "obj"
zip.ExcludeDir ".vs"
zip.ExcludeDir "packages"

// ------------------------------------------------------------
// Create a StringArray containing wildcard exclusion patterns
// for generated files and temporary artifacts.
Dim saExcludes As New Chilkat.StringArray

// Exclude common compiled output files.
success = saExcludes.Append("*.exe")
success = saExcludes.Append("*.dll")
success = saExcludes.Append("*.pdb")
success = saExcludes.Append("*.ilk")
success = saExcludes.Append("*.lib")
success = saExcludes.Append("*.obj")

// Exclude NuGet package files.
success = saExcludes.Append("*.nupkg")

// Exclude temporary, cache, and user-specific files.
success = saExcludes.Append("*.cache")
success = saExcludes.Append("*.tmp")
success = saExcludes.Append("*.user")
success = saExcludes.Append("*.suo")
success = saExcludes.Append("*.log")

// Apply the wildcard exclusion patterns to the Zip object.
zip.SetExclusions saExcludes

// ------------------------------------------------------------
// Recursively add references to the project files.
// 
// AppendFiles does not immediately read or compress the files.
// It adds file references to the Zip object. The referenced files
// are read and compressed later when WriteZipAndClose is called.
Dim recurse As Boolean
recurse = True

success = zip.AppendFiles("c:/projects/MyProject/*",recurse)
If (success = False) Then
    System.DebugLog(zip.LastErrorText)
    Return
End If

// ------------------------------------------------------------
// Write the ZIP archive and close it.
// 
// This is where the referenced source files are actually read,
// compressed as needed, and written to the final .zip archive.
success = zip.WriteZipAndClose()
If (success = False) Then
    System.DebugLog(zip.LastErrorText)
    Return
End If

System.DebugLog("Visual Studio project ZIP created successfully.")