Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Package fails to add reference to project for DLL inside lib directory

Tags:

c#

.net

nuget

dll

I'm attempting to package up a .NET DLL which references a C++ DLL. The nuspec file looks like this:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>MyPackage</id>
    <version>1.0.0</version>
    <authors>some author</authors>
    <owners>some owner</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>.NET Wrapper for rebuilt 64-bit version of MyPackage</description>
    <copyright>Copyright 2014</copyright>
  </metadata>
  <files>
    <file src="x64\MyPackage64.dll" target="content" />
    <file src="MyPackageNET.dll" target="lib" />
  </files>
</package>

When I examine the generated nupkg file, the internal file structure appears correct. The C++ DLL is in content and the .NET DLL is in the lib.

When I install the nupkg into a project, the content DLL is added to the project root and the lib DLL is added to the solution packages directory.

However, no reference is added to the project. I am forced to manually add the reference. I have tried adding the following node to metadata, to no avail:

<references>
  <reference file="MyPackageNET.dll" />
</references>

Am I doing something wrong? I've generated other nuspec & nupkg files from varoius .csproj files, which properly add references to projects in which they've been installed. Is there something about the packaging of individual DLLs I've missed that is keeping a reference from being added to the project?

On a related note, if I cannot automatically add the reference, can anyone direct me to any resources which would explain the syntax of the $project.Object.Reference.Add method, or which would help me programmatically add a reference to the DLL to my project?

like image 559
Victor Wilson Avatar asked May 22 '14 19:05

Victor Wilson


1 Answers

I experienced the same issue with additional symptoms of not being able to uninstall the package. I followed the guidance from Can't uninstall/reinstall NuGet package and added the packages.config file to the project. I had to copy the file from my solution folder as my project didn't have the file yet. Doing this corrected both symptoms.

like image 191
sappster Avatar answered Oct 20 '22 23:10

sappster