(JavaScript) ZIP a Visual Studio Project and Exclude Build Artifacts
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
var success = false;
var zip = new CkZip();
// 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) {
console.log(zip.LastErrorText);
return;
}
// 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.
var saExcludes = new CkStringArray();
// 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.
var recurse = true;
success = zip.AppendFiles("c:/projects/MyProject/*",recurse);
if (success == false) {
console.log(zip.LastErrorText);
return;
}
// ------------------------------------------------------------
// 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) {
console.log(zip.LastErrorText);
return;
}
console.log("Visual Studio project ZIP created successfully.");
|