Version Pinning Isn't Boring: How I Stopped Breaking My Own Builds

I used to be the developer who hit Update-Package with reckless abandon. Every Monday morning, I'd open Visual Studio, see the little yellow badge on the NuGet tab, and think, "Sure, let's see what's new." By Tuesday, I was usually reverting commits, digging through GitHub issues, and explaining to my PM why the staging environment was red. The turning point came when a transitive dependency of a transitive dependency decided to drop support for .NET Framework 4.7.2, and our legacy Windows service just stopped serializing JSON the way it used to. That was the day I started treating version pinning as a first-class engineering practice, not a chore.

This article is about the practical side of that change. I'll walk you through the workflows, the commands, and the failure modes I've hit over the last two years, specifically on Windows with PowerShell and .NET projects. But the principles apply to Node, Python, or anything else where "latest" is a moving target.

The Two Flavors of Pinning: Direct and Transitive

Let's get the terminology straight first, because half the confusion I see on Stack Overflow comes from people mixing these up.

Direct pinning is when you explicitly set a version in your project file or manifest. For .NET, that looks like this in your .csproj:

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> 

That's the easy part. The hard part is transitive pinning. Your project references MyCompany.Utilities, which references Serilog 2.x, which references System.Text.Json 4.7.0. You didn't choose those versions, but they're in your output folder. When the NuGet resolver decides to unify versions, it can pull in something you never explicitly approved.

The classic Windows failure mode here is the "NU1605" warning. I've seen it a dozen times:

NU1605: Detected package version downgrade: System.Text.Json from 8.0.0 to 6.0.0. 

That happens when a direct reference pins System.Text.Json to 8.0.0, but a transitive dependency forces 6.0.0. NuGet will silently pick the lower one unless you add a direct reference to the higher version. The fix is not to "just ignore it" – that's how you get runtime TypeLoadException errors at 3 AM.

My rule now: every direct package reference gets a version. No wildcards, no Version="*". And for transitive dependencies that matter (serializers, logging, HTTP clients), I add explicit <PackageReference> entries just to pin them, even if I never call them directly. It's a bit of boilerplate, but it saves me from mystery updates.

The PowerShell Workflow That Keeps Me Sane

On Windows, I live in PowerShell. Here's the exact script I run at the start of every sprint to get a full picture of what's actually in my dependency tree. It's not fancy, but it's honest.

# List all direct package references with versions dotnet list .\src\MyApp.sln package --include-transitive # Export the full graph to a file for diffing later dotnet list .\src\MyApp.sln package --include-transitive --format json | Out-File -FilePath .\deps-baseline.json -Encoding utf8 

The first command gives me a readable table. The second one dumps a JSON file. I commit that JSON to the repo (yes, really). When a teammate says "I didn't change any packages, why is the build different?" I diff the JSON. Nine times out of ten, the answer is "NuGet restored a newer patch version because you didn't pin."

But wait, there's a subtlety. dotnet list package shows you what NuGet resolved, not what you pinned. If you have Version="13.0.*", the resolved version might be 13.0.5 today and 13.0.9 next week. The JSON baseline captures the resolved version, which is what actually gets compiled. So I also run this to check for floating versions:

# Find any PackageReference with a wildcard version Select-String -Path .\src\**\*.csproj -Pattern '<PackageReference[^>]*Version="[^"]*\*[^"]*"' | ForEach-Object { $_.Line.Trim() } 

If that returns anything, I fix it immediately. Floating versions are a ticking clock. They work fine until they don't, and the "they don't" moment is always when you're about to ship.

When Pinning Bites Back: The Lock File Debate

I'll be honest: pinning everything with exact versions has a downside. It makes upgrades feel like a chore. You have to consciously decide to move from Serilog 2.12.0 to 2.13.1, and you have to test it. That's the point, but it's also friction.

For .NET, the modern answer is packages.lock.json. You enable it per project by adding a property:

<PropertyGroup> <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> </PropertyGroup> 

Once that's set, NuGet generates a lock file that records the exact resolved version of every package, direct and transitive. It's like a package-lock.json for .NET. I've found this to be the most reliable way to get reproducible builds across machines, especially when you have a mix of developers on different SDK versions.

But here's the failure mode that caught me off guard: lock files and floating versions don't mix well. If you have Version="13.0.*" and a lock file, NuGet will respect the lock file and not update. That's actually good. But if you delete the lock file and restore, you might get a different version. So I treat the lock file as the source of truth. When I want to upgrade a package, I deliberately edit the .csproj to a new exact version, then run dotnet restore. NuGet updates the lock file, and I commit both files together.

There's also the CI angle. On our build server, I run a check to ensure the lock file is in sync:

# In CI, fail the build if lock file is out of date dotnet restore .\src\MyApp.sln --force-evaluate if ($LASTEXITCODE -ne 0) { Write-Error "Restore failed. Check lock file." } 

--force-evaluate tells NuGet to re-evaluate the lock file against the project files. If someone edited a .csproj without updating the lock, this fails. It's saved me from at least three "works on my machine" incidents.

Edge Cases That Made Me Swear

I want to share three specific edge cases because they're the kind of thing that doesn't show up in tutorials.

Edge case 1: The "NoOp" trap. NuGet has a concept called "no-op restore." If it thinks nothing changed, it skips the restore entirely. That's great for speed, but it can mask a missing package. I've seen a machine where a package was deleted from a local feed, and the build succeeded because NuGet used a cached copy. The lock file said 13.0.3, but the actual DLL on disk was from 13.0.2. The fix was to add --force to the restore command in CI. It's slower, but it's honest.

Edge case 2: The "latest" feed problem. If you're using a private NuGet feed that includes prerelease packages, a floating version like 1.0.* can resolve to 1.0.1-beta if that's the latest. NuGet doesn't care about stable vs. prerelease when you use a wildcard. My rule: never use wildcards for packages that come from a feed with prerelease versions. Always pin to a specific version, and let the lock file handle the transitive stuff.

Edge case 3: The "we don't use NuGet" scenario. Not everything is .NET. For PowerShell modules, I pin with RequiredVersion in a PSDepend file. For Python, it's pip freeze > requirements.txt. For Node, it's npm ci with a package-lock.json. The principle is the same, but the tooling is different. I've learned to not assume that "pin" means the same thing in every ecosystem. In PowerShell, for example, Install-Module -Name Foo -RequiredVersion 2.1.0 is your friend, but Update-Module will happily upgrade it if you're not careful.

The Human Side of Pinning

Here's what I didn't expect: version pinning is as much about team communication as it is about tooling. When I moved from "always update" to "pin and review," I had to explain to my team why we were suddenly getting "dependency drift" warnings in Dependabot. The answer was, "We're not ignoring security updates – we're just reviewing them before they land."

I now keep a DEPENDENCIES.md file at the root of the repo. It's a simple table that lists every direct dependency, the pinned version, and the date we last reviewed an update. It's not a fancy tool. It's just a text file. But it forces the conversation. When someone proposes a new package, they have to add a row. When a security advisory comes out, we look at the table and decide if the upgrade is worth the risk.

The tooling that actually helped me the most in this journey wasn't a fancy package manager. It was dotnet list package --vulnerable. That command checks your resolved packages against the GitHub Advisory Database. It's not perfect, but it gives me a concrete list of things to look at, and I can map them against my pinned versions. If a vulnerable version is pinned, I know I have to act. If it's a transitive dependency, I know I have to add a direct reference to override it.

Related resource

If you're into Windows desktop applications and want to see how real projects handle versioning in practice, I recommend browsing GitVaults. It's a catalog of open-source Windows software, and you can often see the exact versions of dependencies that projects ship with. For example, check out josefnemec playnite 10 60. Playnite is a game library manager, and its release history shows how a mature project handles version bumps across releases. It's a good reference for what a "stable" pin looks like when you're shipping to real users.

Caveat

I've written this from my own experience, and my setup is specific to .NET on Windows with PowerShell. Your mileage may vary if you're on a different stack or use a different CI system. If you spot a mistake in the commands or the NuGet behavior, please correct me – I'd rather learn from a thoughtful comment than keep repeating a bad habit.