title: Failed to add NuGet package
body: <p>I have created a NuGet package <code>libtidy</code> which is pushed to a Team Services feed. </p>
  
  <p>When I try installing via the NuGet console I get the error </p>
  
  <blockquote>
    <p>Failed to add reference to 'libtidy'</p>
  </blockquote>
  
  <p>I have read this <a href="https://stackoverflow.com/questions/8314400/nuget-add-reference-error-while-installing-packages">Stack Overflow post</a> where the OP has a similar problem but I have been unable to resolve the issue - I've tried:</p>
  
  <ul>
  <li>Deleting all the folders inside of the packages folder and updating</li>
  <li>Executing <code>regsvr32 "C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VsLangproj.olb"</code> from an elevated command prompt</li>
  <li>Doing <code>Uninstall-Package libtidy -force</code> from the package manager console (this doesn't work as the package isn't installed</li>
  <li><code>git clean -dfx</code></li>
  <li>clearing nuget cache</li>
  <li>manually removing the libtidy directory in the .nuget directory</li>
  </ul>
  
  <p>EDIT</p>
  
  <p>Having done a little research, could this be to do with the fact that libtidy.dll is not managed code? Infact it is ANSI-C. In our application we are using TidyManaged, as a wrapper, which is managed, and is successfully installed via nuget. Currently if we manually copy in libtidy.dll into bin, it works fine, but it would be better if the build process pulled in libtidy.dll, perhaps as part of the Tidymanaged install, which it does not at present.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <pre><code>param($installPath, $toolsPath, $package, $project)
  
  $file = $project.ProjectItems.Item("libtidy.dll");
  
  If ($file -eq $null)
  {
       $project.ProjectItems.AddFromFile("libtidy.dll");
       $file = $project.ProjectItems.Item("libtidy.dll");
  }
  
  $file.Properties.Item("CopyToOutputDirectory").Value = [int]1;
  </code></pre>
  
  <p>EDIT3</p>
  
  <p><strong>Edit 3</strong>:</p>
  
  <p>I am </p>
  
  <p>a) placing <code>libtidy.dll</code> and <code>Install.ps1</code> in a directory called <code>nuget-libtidy</code> in the manifest generated by <code>nuget spec</code> </p>
  
  <p>I have:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;package &gt;
    &lt;metadata&gt;
      &lt;id&gt;nuget-libtidy&lt;/id&gt;
      &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;authors&gt;Name&lt;/authors&gt;
      &lt;owners&gt;Name&lt;/owners&gt;
      &lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;
      &lt;description&gt;nuget-libtidy&lt;/description&gt;
      &lt;copyright&gt;Copyright 2016&lt;/copyright&gt;
      &lt;tags&gt;nuget-libtidy&lt;/tags&gt;
    &lt;/metadata&gt;
    &lt;files&gt;
        &lt;file src="libtidy.dll" target="content" /&gt;
        &lt;file src="Install.ps1" target="tools" /&gt;
    &lt;/files&gt;
  &lt;/package&gt;
  </code></pre>
  
  <p>When I run <code>nuget pack</code> I get the following warning:</p>
  
  <pre><code>WARNING: 1 issue(s) found with package 'nuget-libtidy2'.
  
  Issue: Assembly outside lib folder.
  Description: The assembly 'content\libtidy.dll' is not inside the 'lib' folder and hence it won't be added as reference when the package is installed into a project.
  Solution: Move it into the 'lib' folder if it should be referenced.
  </code></pre>
  
  <p>b) When we build the application libtidy.dll is placed in the root of the project (not the bin) &amp; get the following error in the output window:</p>
  
  <pre><code>Added package 'nuget-libtidy' to 'packages.config'
  Executing script file &lt;path&gt;\nuget-libtidy\tools\Install.ps1'...
  Cannot add a link to the file libtidy.dll. There is already a file of the same name in this folder.
  At &lt;path&gt;\nuget-libtidy\tools\Install.ps1:7 char:5
  +     $project.ProjectItems.AddFromFile("libtidy.dll");
  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : OperationStopped: (:) [], COMException
      + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
  
  Successfully installed 'nuget-libtidy' to &lt;Namepace&gt;
  </code></pre>