Visual Basic 6.0
Visual Basic 6.0
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:
bindirectoriesobjdirectories.vsdirectories*.exe,*.dll,*.pdb, and related output files- Temporary and cache files
Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
Dim zip As New ChilkatZip
' 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 = 0) Then
Debug.Print 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 CkStringArray
' 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 Long
recurse = 1
success = zip.AppendFiles("c:/projects/MyProject/*",recurse)
If (success = 0) Then
Debug.Print 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 = 0) Then
Debug.Print zip.LastErrorText
Exit Sub
End If
Debug.Print "Visual Studio project ZIP created successfully."