Sample code for 30+ languages & platforms
VB.NET

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 VB.NET Downloads

VB.NET
Dim success As Boolean = 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
    Debug.WriteLine(zip.LastErrorText)
    Exit Sub
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.
saExcludes.Append("*.exe")
saExcludes.Append("*.dll")
saExcludes.Append("*.pdb")
saExcludes.Append("*.ilk")
saExcludes.Append("*.lib")
saExcludes.Append("*.obj")

' Exclude NuGet package files.
saExcludes.Append("*.nupkg")

' Exclude temporary, cache, and user-specific files.
saExcludes.Append("*.cache")
saExcludes.Append("*.tmp")
saExcludes.Append("*.user")
saExcludes.Append("*.suo")
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 = True

success = zip.AppendFiles("c:/projects/MyProject/*",recurse)
If (success = False) Then
    Debug.WriteLine(zip.LastErrorText)
    Exit Sub
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
    Debug.WriteLine(zip.LastErrorText)
    Exit Sub
End If


Debug.WriteLine("Visual Studio project ZIP created successfully.")