Multiple instances of nuget.exe trying to install the same package in parallel causes a double write (original) (raw)

Scenario
ProjectA and ProjectB each have a packages.config that contain the same package. They each build in parallel. Each checks that the nuget package needs to be installed at the same time and then both try to install it. (they both appear to install it fine.) However the files are written out by both instances of nuget.exe.

(the plus side is this has revealed some bad practices where teams were hard linking from nuget package folders then overwriting the hardlinked file corrupting their nuget package install.)

(The down side is build tracers like buildcop need to now have nuget.exe exclusions for double-writes and doublewriting in practice is problematic especially if projectC thinks the package is installed because it is a large package that projectA installed and projectB is still doing a doublewrite and then projectC ends up doing a read lock on a file that projectB is trying to doublewrite causing an access violation.)

perhaps a mutex or something on the package folder should be created before nuget attempts to install a package.