Search code examples
nugetnuget-packageassembly-references

Reference not added for NuGet package


I've a custom NuGet package (My.Resources) containing an assembly and a dependency on another custom NuGet package (My.Base).

If I install the package, the installation finishes successfully, but the assembly reference is not added. Here is the full output from a Install-Packagecommand:

Attempting to resolve dependency 'My.Base (≥ 1.0.0)'.
Installing 'My.Base 1.0.0'.
Added file 'My.Base.dll' to folder 'My.Base.1.0.0\lib\net45'.
Added file 'My.Base.1.0.0.nupkg' to folder 'My.Base.1.0.0'.
Successfully installed 'My.Base 1.0.0'.
Installing 'My.Rsources 1.1.0-beta0001'.
Added file 'My.Resources.dll' to folder 'My.Resources.1.1.0-beta0001\lib\net45'.
Added file 'My.Resources.XML' to folder 'My.Resources.1.1.0-beta0001\lib\net45'.
Added file 'My.Resources.1.1.0-beta0001.nupkg' to folder 'My.Resources.1.1.0-beta0001'.
Successfully installed 'My.Resources 1.1.0-beta0001'.
Adding 'My.Base 1.0.0' to WindowsFormsApplication8.
For adding package 'My.Base 1.0.0' to project 'WindowsFormsApplication8' that targets 'net45',
>> Assembly references are being added from 'lib\net45'
Added reference 'My.Base' to project 'WindowsFormsApplication8'
Added file 'packages.config'.
Added file 'packages.config' to project 'WindowsFormsApplication8'
Successfully added 'My.Base 1.0.0' to WindowsFormsApplication8.
Adding 'My.Resources 1.1.0-beta0001' to WindowsFormsApplication8.
Added file 'packages.config'.
Successfully added 'My.Resources 1.1.0-beta0001' to WindowsFormsApplication8.

While we have several other custom NuGet Packages structured and build the same way, this is the only one with this behavior. The .nuspec inside the .nupkg looks fine and the assembly is in the correct (net45) folder.


Solution

  • NuGet is treating your NuGet package as a localized NuGet package that only contains language resources. Assemblies in this sort of NuGet package are not referenced.

    If you rename your My.Resources.dll to something like My.Resources2.dll, for example, then NuGet will reference the assembly.

    Basically any file that ends with .resources.dll is considered by NuGet to be a resource assembly will not be referenced when the NuGet package is installed.