InstallCommand - Move MachineCache.Default out of ImportingConstructor

Apr 12, 2012 at 11:32 PM

This may be a little niche, however there was a change to allow overriding the MachineCache default location that was included in 1.7.  

However it looks like plugins to the commandline NuGet.exe never have a chance to set an environment variable as part of their functionality to change this location.  This appears to be due to InstallCommand including a call to MachineCache.Default in its ImportingConstructor.  This essentially means on NuGet.exe instantiation, the singleton MachineCache is newed up prior to anything else being able to set or modify the NuGetCachePath environment variable.  Although you can still modify the environment variable before running NuGet.exe, we have a requirement to set it per feed dynamically.

Fix proposal would be to move the instantiation of the MachineCache.Default from the constructor down to a location closer to its use, and to keep existing functionality for unit tests, tweak the constructors such that a Mock Cache can still be passed in.

Already have an initial cut of the code, just wanted to see if there were any issues with this approach.  If not, I will ready a pull request and send one through.

For completeness, this probably also needs to be done in PackageRestoreManager and RecentPackagesRepository as well, however as it is in the VS space I am not sure the same issue applies.