title: How to restore assemblies from a NuGet package for a specific target framework only
body: <p>I'm looking for a way to restore the assemblies for a NuGet package which targets <strong>exactly one</strong> framework, in this case <strong>net45</strong>.</p>
  
  <p>This is my packages config:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" /&gt;
  &lt;/packages&gt;
  </code></pre>
  
  <p>This is my NuGet config file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;config&gt;
          &lt;add key="repositoryPath" value=".\Nuget" /&gt;
      &lt;/config&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Version is: <code>NuGet Version: 5.2.0.6090</code></p>
  
  <p>Running: <code>nuget restore packages.config -ConfigFile nuget.config</code> restores the assemblies for all <code>targetframework</code> versions as can be seen by:</p>
  
  <pre><code>E:\Tmp\NuGet\Nuget\Newtonsoft.Json.12.0.1&gt;dir lib
   Directory of E:\Tmp\NuGet\Nuget\Newtonsoft.Json.12.0.1\lib
  
  2019-09-30  18:27    &lt;DIR&gt;          .
  2019-09-30  18:27    &lt;DIR&gt;          ..
  2019-09-30  18:27    &lt;DIR&gt;          net20
  2019-09-30  18:27    &lt;DIR&gt;          net35
  2019-09-30  18:27    &lt;DIR&gt;          net40
  2019-09-30  18:27    &lt;DIR&gt;          net45
  2019-09-30  18:27    &lt;DIR&gt;          netstandard1.0
  2019-09-30  18:27    &lt;DIR&gt;          netstandard1.3
  2019-09-30  18:27    &lt;DIR&gt;          netstandard2.0
  2019-09-30  18:27    &lt;DIR&gt;          portable-net40+sl5+win8+wp8+wpa81
  2019-09-30  18:27    &lt;DIR&gt;          portable-net45+win8+wp8+wpa81
  </code></pre>
  
  <p>According to <a href="https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#matching-assembly-versions-and-the-target-framework-in-a-project" rel="nofollow noreferrer">docs.microsoft.com</a></p>
  
  <blockquote>
    <p>When NuGet installs a package that has multiple assembly versions, it
    tries to match the framework name of the assembly with the target
    framework of the project.</p>
    
    <p>If a match is not found, NuGet copies the assembly for the highest
    version that is less than or equal to the project's target framework,
    if available. If no compatible assembly is found, NuGet returns an
    appropriate error message.</p>
    
    <p>For example, consider the following folder structure in a package:</p>
  
  <pre><code>\net45
    \MyAssembly.dll
  \net461
    \MyAssembly.dll 
  </code></pre>
    
    <p>When installing this package in a project that targets .NET Framework
    4.6, NuGet installs the assembly in the net45 folder, because that's the highest available version that's less than or equal to 4.6.</p>
    
    <p>If the project targets .NET Framework 4.6.1, on the other hand, NuGet
    installs the assembly in the net461 folder.</p>
  </blockquote>
  
  <p>From the paragraph above I understand that when I set the target framework I should be able to restore just the assemblies for that one target framework. In my case it looks like NuGet completely ignores the <code>targetFramework</code> attribute and always installs the dlls for all target frameworks. Changing it from <strong>net45</strong> to <strong>net40</strong> has no effect.</p>
  
  <p>How can I make NuGet restore <strong>ONLY</strong> the dlls in a package for a specific target framework?</p>