Tired of Accidentally Zipping Build Artifacts? Try 'dnx zipsrc'!
Source: Dev.to
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 500 MB?
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 also 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.
Intelligent Naming
Don’t want to think about file names? Neither do I.
When you run dnx zipsrc without specifying an output name:
- If the folder contains a
.slnor.slnxfile, the zip is named after that solution. - Otherwise, it uses the folder name.
If a MyProject.zip already exists, 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 added automatically 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
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. Existing options include:
- 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 another tool? Here’s what motivated me:
- Naming conventions & output location – Existing tools often have opinionated defaults. I wanted control over naming logic (auto‑using the solution file name) and precise output placement.
- No auto‑incrementing for repeated runs –
dnx zipsrcautomatically appends(2),(3), etc., so you never lose a previous archive. - Better default ignore rules – When there’s no
.gitignore, some tools have minimal exclusions.dnx zipsrcfalls back to comprehensive defaults equivalent todotnet new gitignore.
These may seem like small details, but when you zip projects multiple times a day, they 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 so I didn’t have to reinvent the wheel.
`.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!*