© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
31 replies
PixxelKick

Decoupling Nuget Packages from .csproj for Docker Optimization

Aight so this is a puzzle I have been noodling on for awhile and I am curious if anyone has come up with an easy to maintain, platform agnostic solution that doesnt add additional onboarding steps for new developers.

Which means:
1. It doesnt require a powershell or bash script
2. It doesnt require installing of extra software on the machine
3. Literally just
docker build
docker build
should be sufficient enough to achieve the desired result

The challenge:

Right now, nuget packages are tightly coupled to a .csproj file for projects. csproj files also handle a lot of other random stuff like file includes and build steps and whatnot.

When you try and optimize a dockerfile, you typically start things off via these 4 steps:
1. Copy just the .csproj over
2.
nuget restore
nuget restore
the project to load in nuget packages, which takes a long time usually for large projects
3. Okay now copy all the rest of the project over
4.
dotnet publish
dotnet publish
to build the project

This has the upside of optimizing out the nuget packages as a "cached" first couple layers, so theoretically steps 1 and 2 only ever run if you make changes to the nuget packages...

Except... any modification to the .csproj file itself will still trigger a recache of steps 1-2 as it "dirty"s step 1, since the file's hash has changed.

And turns out, a whole lot of random stuff can cause your .csproj file to change...

So, is there a way you:
1. sanely and easily extract out all the nuget package data to its own file, that only gets changes specifically when nuget packages get changed, uninstalled, added, updated
2. Keep the rest of the project intact and a fresh git checkout of the project still can build and run as is with visual studio (if you run it, it will still be able to automatically detect missing packages and install them for local dev)

Thoughts?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Nuget packages
C#CC# / help
15mo ago
API versioning from NuGet Packages
C#CC# / help
2y ago
Help with NuGet Packages
C#CC# / help
2y ago
❔ Globally Update Nuget Packages
C#CC# / help
3y ago