Project with .nuspec and dependency on third party DLL

Jan 6, 2012 at 8:42 PM

See http://stackoverflow.com/questions/8764236/nuget-add-external-reference if you want rep :)

If you didn't read, or to summarize:

Folder structure:
My.Project.csproj
My.Project.nuspec
lib\Third.Party.dll
bin\Debug\My.Project.dll
bin\Debug\Third.Party.dll
bin\Debug\lib\Third.Party.dll #this is only here as a test to see if nuget wants it here 


MyProject.csproj references Third.Party.dll and needs to make sure the new project references it. There is no nuget package for Third.Party.dll.

<references> <reference file="Third.Party.dll" /> </references>

When I try to pack  
>nuget pack My.Project.csproj

It tells me that it can't find lib\Third.Party.dll

What's the right way to organize this so it can find it and creates the reference correctly?
What if I wanted to organize this so that it just *copies* the dll and doesn't create a new project reference (because I can wrap any calls to Third.Party.dll objects and methods with the objects and methods from my application)? 

Jan 9, 2012 at 10:05 AM

The <references> element is for a different purpose than what you need here. See the "Specifying Explicit Assembly Reference" in this page http://docs.nuget.org/docs/reference/nuspec-reference for more details.

Jan 9, 2012 at 10:15 AM

If you want to include Third.Party.dll in your package, you need to add it explicitly to the <files> section.

<?xml version="1.0"?>
<package >
<metadata>
  <id>$id$</id>
  <version>$version$</version>
  <title>$title$</title>
  <authors>$author$</authors>
  <owners>$author$</owners>
  <requireLicenseAcceptance>false</requireLicenseAcceptance>
  <description>$description$</description>
  <releaseNotes>Locked against log4net 1.2 - less than 1.2.11 which has breaking changes</releaseNotes>
  <copyright>Copyright 2012  blah blah</copyright>
  <dependencies>
    <dependency id="log4net" version="[1.2,1.2.11)" />
    <dependency id="My.Other.Project" />
  </dependencies>
</metadata>
<files>
  <file src="lib\Third.Party.dll" target="lib\net40" />
</files>

Jan 9, 2012 at 12:41 PM
dotnetjunky wrote:

The <references> element is for a different purpose than what you need here. See the "Specifying Explicit Assembly Reference" in this page http://docs.nuget.org/docs/reference/nuspec-reference for more details.

"Use the <references /> element to explicitly specify assemblies that the target project should reference."

Sounds like exactly what I want (unless I refactor so that the final project doesn't need to talk to Third.Party but just to My.Package). So how is this not what I want? 

Jan 9, 2012 at 1:11 PM

So I added it to <files> and I can see it shows up in the packages folder, but it's not copied over to the bin folder when I compile, which makes sense because there is no reference to it anywhere. So aside from manually adding the reference to the destination project, am I missing some easier solution here? It still sounds like what I want is <references /> but I can't get it to actually pick up a library from a lib folder.

Jan 9, 2012 at 10:05 PM

What is the package structure look like after you create the package? When you install it into a project, does the project reference both assemblies?

Jan 10, 2012 at 12:37 PM

When I install it into a project, the project has a reference to My.Package but not Third.Party. The packages/My.Package/lib folder has both DLLs. I could manually add a reference to something like ../../packages/My.Package/lib/net20/Third.Party.dll but I'm trying to avoid that.

As a workaround, I created my own Third.Party.nupkg which works, because My.Package can depend on that like it depends on log4net, and then everybody's happy, but that seems like it's overkill for the scenario that I want.

Jul 25, 2012 at 10:48 PM

Hi Bussemac

 

I had the same problem and here's how I solved it. Seemed odd to me but it looks like it works and I don't need to create a nuget package for my third party assembly this way.

 

My .nuspec looks like this:

 

<?xml version="1.0"?>
<package >
    <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <title>$title$</title>
        <authors>$author$</authors>
        <owners>$author$</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>$description$</description>
        <releaseNotes>Some release notes</releaseNotes>
        <copyright>Copyright 2012</copyright>
        <tags>some,tags</tags>
        <references>
            <reference file="thirdparty.dll"></reference>
            <reference file="ThisAssemblyName.dll"></reference>
        </references>
    </metadata>
    <files>
        <file src="web.config.transform" target="content"/>
        <file src="lib\net40\thirdparty.dll" target="lib\net40"/>
    </files>
</package>

As you can see - I had to add a file node to copy my thirdparty dll to the target lib\net40 (in my case) folder. Then I had to add "reference" nodes for both the thirdparty.dll as well as the assembly that this NuGet package was creating. 


I hope that helps!

Thanks

Mustafa