This project is read-only.

NuGet command line forces package restore



This issue comes into picture if you download NuGet powertools and enable package restore. On this action the NuGet command line tool is downloaded in a directory named as ".nuget" along with the NuGet target file. Further the .csproj or .vbproj file is modified to import the NuGet target file and to add this property


Once you have enabled package restore do this
  1. Open up the .csproj file in notepad++ or any text editor that can detect changes in the file if carried out by an external program
  2. Disable package restore by firing "disable-packagerestore" from the VS Package Manager Console command line
  3. You will notice that the RestorePackages tag is now set as False.
  4. Close down Visual Studio and open it up again (You must close down VS and not simply the solution)
  5. Open up the same project/solution again. Check notepad++, the tag is still false.
  6. Open up the Package Manager Console. Don't do anything else.
  7. Check back notepad++, the tag is now flipped back to true.
Basically once you have enabled package restore, there is no going back. Every time you open up Package Manger Console, the RestorePackages tag is switched back to True.


nikrox wrote Mar 12, 2012 at 10:51 PM

To complete the analysis - if you edit the project file to remove the Nuget target file import and then rename/delete the .nuget directory this problem goes away.

JeffHandley wrote Mar 13, 2012 at 9:46 PM

NuGet proper doesn't respect the disable-packagerestore command from the power tools. The supported approach for turning package restore off is to remove the build task for the restore operation.

** Closed by JeffHandley 03/13/2012 1:46PM

nikrox wrote Mar 14, 2012 at 10:32 AM


Let me rephrase - NuGet power tools have nothing to do with this. They were mentioned simply so that you get this magic .nuget folder.

The problem is that if you have this .nuget folder then every time you open up the package manager console it will iterate through all the projects in your solution and add the <RestorePackages> tag and the import tag to import the Nuget target file.

You do not have to use power tools. Create a new VS solution, next to where the solution file is add tihs .nuget folder, copy NuGet.exe, NuGet.settings.targets, Nuget.targets file into it. Create an "empty" folder "packages" next to the .nuget folder, now go back into your VS and open up package manager console. You will see that the project file has been modified to add the restorpackages and import nuget target tag.

nikrox wrote Mar 14, 2012 at 10:33 AM

I have explained the reason for re-opening this in my latest comment. Nu Get power tools have nothing to do with this bug. They were mentioned simply so that you get this magic .nuget folder.

aldion wrote Mar 21, 2012 at 8:10 PM

No really related to "disable-packagerestore" I switched the parameter manually.

In short :

The parameter is switched on because EnablePackageRestore is called when NuGet gets initialized.

In details :

The Initialize method checks that :
        // when NuGet loads, if the current solution has package 
        // restore mode enabled, we make sure every thing is set up correctly.
        // For example, projects which were added outside of VS need to have
        // the <Import> element added.
Note here that Restore Mode is thought to be enabled because the check is on .nuget\nuget.exe and .nuget\nuget.targets and not on projects property.

And from there EnablePackageRestore is called and the RestorePackages property is switched on :
        SetMsBuildProjectProperty(project, buildProject, "RestorePackages", "true");
NuGet.VisualStudio.dll!NuGet.VisualStudio.PackageRestoreManager.EnablePackageRestore(EnvDTE.Project project) Line 261 C#
NuGet.VisualStudio.dll!NuGet.VisualStudio.PackageRestoreManager.EnablePackageRestore(EnvDTE.Project project, NuGet.VisualStudio.IVsPackageManager packageManager) Line 246 + 0xb bytes  C#
NuGet.VisualStudio.dll!NuGet.VisualStudio.PackageRestoreManager.EnablePackageRestore() Line 232 + 0xe bytes C#
NuGet.VisualStudio.dll!NuGet.VisualStudio.PackageRestoreManager.EnableCurrentSolutionForRestore(bool quietMode) Line 137 + 0x8 bytes    C#
NuGet.Tools.dll!NuGet.Tools.NuGetPackage.Initialize() Line 106 + 0x1c bytes C#
Microsoft.VisualStudio.Shell.10.0.dll!Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsPackage.SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp) + 0x41 bytes 
[Native to Managed Transition]  
[Managed to Native Transition]  
Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage() + 0xe2 bytes 
Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent() + 0xb0 bytes   
Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.EnsureContentConstructed() + 0x61 bytes   
Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.Activate() + 0x65 bytes   
Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.viewManager_ActiveViewChanged(object sender, Microsoft.VisualStudio.PlatformUI.Shell.ActiveViewChangedEventArgs e) + 0x160 bytes 
Microsoft.VisualStudio.Shell.10.0.dll!Microsoft.VisualStudio.PlatformUI.ExtensionMethods.RaiseEvent<System.__Canon>(System.EventHandler<System.__Canon> eventHandler, object source, System.__Canon args) + 0x14 bytes  
Microsoft.VisualStudio.Shell.ViewManager.dll!Microsoft.VisualStudio.PlatformUI.Shell.ViewManager.SetActiveView(Microsoft.VisualStudio.PlatformUI.Shell.View view, Microsoft.VisualStudio.PlatformUI.Shell.ActivationType type) + 0x9e bytes 
Microsoft.VisualStudio.Shell.ViewManager.dll!Microsoft.VisualStudio.PlatformUI.Shell.ViewManager.OnTabItemMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs args) + 0x4b bytes 
Microsoft.VisualStudio.Shell.ViewManager.dll!Microsoft.VisualStudio.PlatformUI.Shell.ViewManager..cctor.AnonymousMethod__16(object sender, System.Windows.Input.MouseButtonEventArgs args) + 0x36 bytes 
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x31 bytes    
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x35 bytes  
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x42 bytes    
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) + 0x12f bytes  
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) + 0x73 bytes  
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) + 0x3f bytes   
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted) + 0x42 bytes    
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x210 bytes   
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) + 0x45 bytes 
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0x64 bytes  
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) + 0x1ef bytes 
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x37d bytes 
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x67 bytes   
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0xa4 bytes    
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x6f bytes    
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x53 bytes 
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x3d bytes    
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0xa5 bytes  
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) + 0x38 bytes 
mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x56 bytes 
[Native to Managed Transition]  
[Managed to Native Transition]  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xb2 bytes  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x2c bytes    
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x5d bytes  
WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherOperation operation, System.Threading.CancellationToken cancellationToken, System.TimeSpan timeout) + 0x49 bytes  
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0xef bytes  
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0xf1 bytes 

It's related to another issue asking for Package Restore mode to be on only for some projects...

JeffHandley wrote Mar 27, 2012 at 9:14 PM

Moving this to backlog, but we should keep this in mind and watch for more votes.

aldion wrote Apr 7, 2012 at 2:44 AM

This causes an issue in Nuget 1.8 : If a user loads a project that has restore enabled, then the restore package consent is automatically switched on because EnablePackageRestore is called when NuGet gets initialized.

pontusm wrote Apr 19, 2012 at 7:35 AM

Maybe nuget power tools could do this automatically then?