58

I'm going to bang out a couple of questions here...first, with NuGet is it possible to create a package from a few DLLs? There is no visual studio project, just the command line and a couple of pre-compiled DLL files.

Second, assuming that is possible, why do I continuously get the "Assembly outside of the lib folder" warning? I've tried everything I can think of to get associated assemblies to add themselves as references inside of the NuGet package.

My file structure looks like this

 Root
   - File1.dll
   - lib
     - File2.dll
     - File3.dll

When I tell NuGet to pack it using a .nuspec like this

<?xml version="1.0"?>
<package >
  <metadata>
    <id>File1.dll</id>
    <version>1.0.0</version>
    <authors>thisguy</authors>
    <owners>thisguysmom</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>This is some library</description>
    <releaseNotes>Porting to NuGet</releaseNotes>
    <copyright>Copyright 2012</copyright>
    <references>
      <reference file="File2.dll" />      
      <reference file="File3.dll" />
    </references>
  </metadata>
</package>

I receive that warning. From what I'm reading, I shouldn't even have to define the references node in any of my projects, as the lib folder items should automatically be added as references?

Does anyone out there understand this NuGet mess?

farina
  • 3,486
  • 6
  • 32
  • 44

8 Answers8

20

I just ran into this problem. Nuget is expecting a structure that looks like:

root
  - lib
    - net40
      - File1.dll
      - File2.dll
      - File3.dll

net40 or net20 or net45 as appropriate to your .net version.

run

nuget pack yourlibrary.nuspec

to package it up.

That will pack up the dir wholesale and put it in the nupkg. The error messages will disappear at that point.

Jason Wall
  • 571
  • 1
  • 6
  • 15
  • 8
    Where is the supported list of `net20`, `net40`, `net45`, … maintained? Do these just prevent inclusion of the assembly into an older project when added (as opposed to just putting the files under `lib`)? When building the package, is this additional structure typically maintained manually, or can the .NET version of the assembly be detected and used? – brianary Mar 16 '15 at 16:52
  • 4
    @brianary i believe that list is here: https://learn.microsoft.com/en-us/nuget/schema/target-frameworks#supported-frameworks and this link more fully documents the above folder structure: https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks – Jason Wall Feb 03 '17 at 03:44
  • Here net40 shows the framework on which File*.dll are built?? OR the framework of the project where you are going to use/reference these (File*.dll) dlls ?? – gmuhammad Oct 18 '17 at 11:44
  • @gmuhammad I believe the net40 indicates the framework version the project was built under. – Jason Wall Apr 01 '19 at 01:19
17

Any dll that you want referenced should be under the lib folder. The warning is because file1.dll is outside lib and will be ignored during package installation. (Other special folder are "content" and "tools")

I'd used this structure :

Root
  - lib
    - File1.dll
    - File2.dll
    - File3.dll

See : http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Package_Conventions for additional details.

Alexandre Dion
  • 9,130
  • 2
  • 41
  • 29
  • 50
    sorry, but what lib folder? I have been following this tutorial (http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package) for creating a package from an assembly and don't see any lib folders - just a command to create a spec file and then a nupkg file – DevDave Jul 23 '13 at 12:16
15

With the version of NuGet that is current as of this post (and I assume later versions as well), you can use the .csproj file, in tandem with the .nuspec file to create the package. What we did was make a .nuspec file (using nuget spec and then customizing it) and include it in the project.

With the customized .nuspec file, we used the command:

nuget pack sample.csproj -IncludeReferencedProjects

At that point it built the .nupkg and did not emit issues. The .nupkg file showed up in the normal output folder (in my default case, bin\debug).

Prof Von Lemongargle
  • 3,658
  • 31
  • 29
  • 1
    This is a poor answer. With VS 2015 using nuget 3.3 and your exact command, I still get this error. – Mario Apr 06 '16 at 19:52
  • It worked for me though. I created the *.csproj.nuspec file from the *.csproj file with "nuget spec" and did NOT rename it. Only when I tried to rename it I got the error. – henon May 10 '20 at 11:30
13

You may add references to another dll by adding below inside tag in nuspec file

<package>
   <metadata>
      ...
</metadata>
<files>
 <file src="..\ReferencedFolder\*.*" target="lib\net40\" />
</files>
</package>
Madhu Ranjan
  • 17,334
  • 7
  • 60
  • 69
  • I found that `src="../Xxx" ...` didn't work (even though the docs say it should); but since `src` is relative to the `BasePath` parameter you can change `BasePath` to a root of all the files you want to include. – Richard Barnett May 29 '15 at 07:50
  • This works very well if you already have built the assemblies and need to just package them. – henon May 10 '20 at 14:52
1

Alexandre is referring to the "lib" folder that gets created when you create a NuGet package. You can open the .nupkg just like you would any zip file. In there, you will see a lib\netXX folder where XX is the version of the .NET framework you're targeting. So when you're packing your NuGet file, make sure File1.dll is inside the lib folder.

Adam S
  • 121
  • 3
1

I used Prof Von Lemongargle' solution, and for me was a great solution. Important:

  1. Include spec file (with right-click-> Include in project) in the project
  2. Give to spec file THE SAME FILENAME of your project (myproject.csproj, myproject.nuspec)

This work perfectly in Visual Studio 2012.

0

They get into the "lib" folder by being included in your bin\debug or bin\release folder in .NET. So you need to get the project compile to copy local on the external DLLs so it includes them in the bin folder on compile.

user3683706
  • 93
  • 1
  • 7
0

If dependencies or libraries have been changed, old files affect the packaging operation.

  1. Remove obj and bin folders from project.
  2. Run dotnet restore
  3. Run nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects or your command whatever.
Hayrullah Cansu
  • 262
  • 5
  • 14