The Problem Every Developer Knows
We've all been there. You need to quickly share your project with a colleague, attach it to a support ticket, or upload it somewhere. You right-click, select "Compress to ZIP," and then... wait. Why is it taking so long? Why is the file 500MB?
Oh right. You just zipped node_modules. Or bin/obj. Or that massive .nuget cache.
Now you have to manually exclude folders, or worse, copy everything to a new location first. What should take 5 seconds becomes a 5-minute ordeal.
Introducing dnx zipsrc ๐
dnx zipsrc is a smart CLI tool that creates zip archives containing only your source code. It automatically excludes build outputs, dependencies, and other artifacts you don't want to share.
The best part? With .NET 10's new dnx command, you don't even need to install it first!
dnx zipsrc
That's it. One command. Your source code is now neatly packaged in a zip file, ready to share.
How It Works
Smart Exclusion with .gitignore
Instead of reinventing the wheel, dnx zipsrc leverages your existing .gitignore patterns. If your project has a .gitignore file, those rules are automatically honored.
No .gitignore? No problem! The tool falls back to sensible defaults equivalent to dotnet new gitignore, covering common patterns for:
-
C#/.NET:
bin/,obj/,*.user,*.suo,.vs/ -
Node.js:
node_modules/,dist/,.cache/ - And many more: Build outputs, IDE files, logs, etc.
It even respects .gitignore files in subdirectories and correctly handles negation patterns (!important-file.txt).
Under the hood, this is powered by GitignoreParserNet, a robust .gitignore parser library for .NET. It handles all the edge cases so I didn't have to reinvent that wheel!
Intelligent Naming
Don't want to think about file names? Neither do I.
When you run dnx zipsrc without specifying an output name:
- If your folder contains a
.slnor.slnxfile, the zip is named after that solution - Otherwise, it uses the folder name
Already have a MyProject.zip? The tool automatically creates MyProject (2).zip instead of overwriting.
Usage Examples
Zip the Current Directory
dnx zipsrc
Zip a Specific Directory
dnx zipsrc -d ./src/MyAwesomeApp
Specify a Custom Output Name
dnx zipsrc -d ./src/MyApp -n ./archives/MyAppSource
# Creates: ./archives/MyAppSource.zip
The .zip extension is automatically added if you forget it!
Why dnx Instead of dotnet tool install?
.NET 10 introduced the dnx command, which lets you run .NET global tools without installing them first. It downloads, caches, and runs the tool in one step.
This means:
- โ No cluttering your global tools list
- โ Always runs the latest version
- โ Works immediately on any machine with .NET 10+
- โ Perfect for one-off tasks like zipping source code
Of course, if you use it frequently, you can still install it the traditional way:
dotnet tool install -g zipsrc
zipsrc -d ./MyProject
Real-World Use Cases
- ๐ง Email attachments: Share clean source code without the bloat
- ๐ซ Support tickets: Attach minimal reproductions to bug reports
- ๐ Teaching: Distribute starter projects to students
- ๐พ Quick backups: Archive your work before major refactoring
- ๐ค Code reviews: Share snapshots with teammates who aren't on your repo
"But Wait, Doesn't This Already Exist?"
You're right! Tools for zipping source code aren't new. There are already some options out there:
- Zipper Extension - A Visual Studio add-in that can zip your solution
- dotnet-zip-source - A .NET global tool with similar goals
So why create yet another tool? Here's what motivated me:
1. Naming Conventions and Output Location
Existing tools often have opinionated defaults for where the zip file goes and what it's named. I wanted control over the naming logicโspecifically, automatically using the solution file name when available, and placing the output exactly where I expect it.
2. No Auto-Incrementing for Repeated Runs
When I zip a project multiple times (maybe after making changes), I don't want to manually rename files or have the previous archive overwritten. dnx zipsrc automatically appends (2), (3), etc., so you never lose a previous archive.
3. Better Default Ignore Rules
When there's no .gitignore file, some tools have minimal or no exclusion rules. dnx zipsrc falls back to comprehensive defaults equivalent to dotnet new gitignore, which covers a much wider range of common artifacts out of the box.
These might seem like small things, but when you're zipping projects multiple times a day, these little conveniences add up!
Requirements
- .NET SDK 10.0 or later
Get Started Now!
Ready to stop accidentally zipping node_modules? Just run:
dnx zipsrc
Check out the project on GitHub: jsakamoto/dnx-zipsrc
Install from NuGet: zipsrc on nuget.org
Have questions or feedback? Drop a comment below or open an issue on GitHub. Happy zipping! ๐๏ธ
Acknowledgments
Special thanks to Guiorgy for creating GitignoreParserNet. This library handles all the complex .gitignore parsing logic, making it easy to build tools that respect ignore patterns correctly. Open source makes building tools like this so much easier! ๐
This article was written with the help of VS Code and GitHub Copilot (Claude Opus 4.5 model). As a Japanese developer who is not a native English speaker, I appreciate your understanding if there are any awkward expressions!
Top comments (0)