How to remove NuGet after enabling “NuGet without committing packages to source control”?

In order to prevent committing libraries to source control, the recommended method on the NuGet site is to “Enable NuGet package restore“. The official article covering this can be found on the NuGet site.

Basically NuGet package restore is enabled by right-clicking on a solution file and selecting “Enable NuGet package restore”. Once enabled, NuGet does two things. It adds a .nuget folder to the solution, which contains a MSBuild file and the NuGet application. A packages folder is also created in the solution directory and contains all the libraries that are managed by NuGet.

Once this library management method has been trialed you may decide that you prefer to revert to the previous manner of using NuGet, however there’s no “disable” option in the Visual Studio context menu. So in order to disable NuGet package restore simply follow these steps:

Step 1:

  • Use a text editor to edit the project file i.e. Project1.csproj
  • Remove the 3 lines highlighted in the sample project file below (line 16,17 & 52)
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  <Target Name="AfterBuild">

Step 2: (Optional)

This step is solely for cleanup purposes.
  • Remove the packages folder in the solution’s root folder. (Optional, unless you wish to keep the downloaded libraries)
  • Remove the .nuget folder from the solution’s root folder. (Optional, but why keep it?)

That’s it! Your solution should now be free from NuGet package restore. It can always be enabled again should you regret this decision.

One Comment on “How to remove NuGet after enabling “NuGet without committing packages to source control”?”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: