1

I have created a Nuget package using Nuget Package Explorer. The package has some third party dlls that I use in my code. I dlls are included in the Nuget package and not referenced directly in the project references. The Nuget Package has the following.

 - thirdPartyAAA.dll
 - thirdPartyAAA.xml (Needed by thirdPartyAAA.dll)
 - thirdPartyBBB.dll (needed by thirdPartyAAA.dll
 - thirdPartyBBB.dll.config (used by thirdPartyBBB.dll)
 - Dependency on HtmlAgilityPack nuget (Needed by thirdPartyAAA.dll)
 - Dependency om RestSharp nuget (Needed by thirdPartyAAA.dll)

The problem is: when I reference this Nuget package in the code and compile the code I only get aaa.dll in the bin output folder. the following files are missing from the bin folder:

 - thirdPartyAAA.xml
 - thirdPartyBBB.dll
 - thirdPartyBBB.dll.config
 - All dlls from HtmlAgilityPack nuget
 - All dll from RestSharp nuget

In my code I directly reference thirdPartyAAA.dll.

Is there a way - either during creating the Nuget Package or when referencing the package - to force the Nuget Package to restore all its contents and its dependencies? I need all the files that's included in the Nuget Package to be restored regardless if they are directly references in the code or not.

thank you all for your help. Here is the manifest of the package if it helps.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyPackage</id>
    <version>1.0.0</version>
    <title></title>
    <authors>Dev</authors>
    <owners>Dev</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>My package description.</description>
    <dependencies>
      <dependency id="HtmlAgilityPack" version="1.4.9" />
      <dependency id="RestSharp" version="105.0.1" />
    </dependencies>
  </metadata>
  <files>
    <file src="content\thirdPartyAAA.chm" target="content\thirdPartyAAA.chm" />
    <file src="content\thirdPartyAAA.XML" target="content\thirdPartyAAA.XML" />
    <file src="content\thirdPartyBBB.dll.config" target="content\thirdPartyBBB.dll.config" />
    <file src="lib\thirdPartyAAA.dll" target="lib\thirdPartyAAA.dll" />
    <file src="lib\thirdPartyBBB.dll" target="lib\thirdPartyBBB.dll" />
  </files>
</package>
Dev Dev
  • 135
  • 2
  • 8
  • Any update for this issue? Have you resolved this issue? If not, would you please let me know the latest information about this issue? – Leo Liu Apr 24 '18 at 02:19

4 Answers4

1

The problem is: when I reference this Nuget package in the code and compile the code I only get aaa.dll in the bin output folder. the following files are missing from the bin folder:

 - thirdPartyAAA.xml
 - thirdPartyBBB.dll
 - thirdPartyBBB.dll.config
 - All dlls from HtmlAgilityPack nuget
 - All dll from RestSharp nuget

First, for the thirdPartyBBB.dll, you should make sure the target framework version of project is higher than your dll's target framework. For example, If the target framework version of your project is .net 4.6.2, the target framework version of your thirdPartyBBB.dll should be lower than .net 4.6.2. Otherwise, you are referring a dll file with higher version target framework to the project with lower version target framework. This is incompatible.

Besides, for the dependencies of this package, you can check if those dependencies added to the project, and the properties Copy Local of those dlls are set to True. It works fine on my side.

Second, for the content file, you should add a .targets file in the build folder in your package with following code to copy those content files to the bin folder:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="$(ProjectDir)thirdPartyAAA.chm">
      <Link>thirdPartyAAA.chm</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CustomToolNamespace></CustomToolNamespace>
    </None>
    <None Include="$(ProjectDir)thirdPartyAAA.XML">
      <Link>thirdPartyAAA.XML</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CustomToolNamespace></CustomToolNamespace>
    </None>
    <None Include="$(ProjectDir)thirdPartyBBB.dll.config">
      <Link>thirdPartyBBB.dll.config</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CustomToolNamespace></CustomToolNamespace>
    </None>
  </ItemGroup>
</Project>

For some details info, please check this thread.

Alternatively, you can use Install.ps1 file to change the property, the script looks like:

param($installPath, $toolsPath, $package, $project)

function MarkDirectoryAsCopyToOutputRecursive($item)
{
    $item.ProjectItems | ForEach-Object { MarkFileASCopyToOutputDirectory($_) }
}

function MarkFileASCopyToOutputDirectory($item)
{
    Try
    {
        Write-Host Try set $item.Name
        $item.Properties.Item("CopyToOutputDirectory").Value = 2
    }
    Catch
    {
        Write-Host RecurseOn $item.Name
        MarkDirectoryAsCopyToOutputRecursive($item)
    }
}

#Now mark everything in the a directory as "Copy to newer"
MarkDirectoryAsCopyToOutputRecursive($project.ProjectItems.Item("TheFolderOfYourContentFiles"))

You can check similar issue for details.

In addition, I have created a test nuget package, you can check if it works for you, test it with .net framework project with target framework 4.6 and above.

https://1drv.ms/u/s!Ai1sp_yvodHf1QJriMiGQWdYveRm

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
0

Go to your solution explorer , on Ur project references, right click on the DLL which is missing from the bin folder. Select properties, then make "copy local " to true. This will copy the DLL to the build path after compiling.

S.Frank Richarrd
  • 488
  • 1
  • 3
  • 15
  • Sorry, this not what I'm asking. I'm talking about that the Nuget package doesn't restore some of its dlls as it suppose to. – Dev Dev Apr 17 '18 at 19:42
0

Go to your solution explorer , on Ur project references, right click on the DLL which is missing from the bin folder. Select properties, then make "copy local " to true. This will copy the DLL to the build path after compiling.

For nuget restoring please refer the below link

https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting

S.Frank Richarrd
  • 488
  • 1
  • 3
  • 15
0

I recently ran into almost exactly the same problem.

After 2 days, I discovered several posts that clarified that the contents folder are ONLY deployed during the +initial+ installation of the nuget.

What this means is that any files deployed as CONTENT are intended to be checked into your version control system, just like any other code in your project.

They are specifically NOT deployed when VS runs a "package restore" as it does when you build a project and some packages are missing.

DarinH
  • 4,868
  • 2
  • 22
  • 32