Reference unsigned NuGet package within a signed assembly
If you want to add a reference to an unsigned NuGet package from a signed assembly you need to take a few steps to make it possible.
In summary, what we need to do is, take the assembly from NuGet we want to reference, merge its dependencies onto it, sign it and repackage it.
- Save as into a known location
- On the package metadata, download all the dependencies by clicking on each one of them in the dependency list and then the download link
- locate all the dependencies dlls as well
- Extract the resulting main .nupkg file (as a zip) into a folder
- Locate the assembly file, keep that location
- Open ILMerge GUI
- Add the main assemblies and all the dependencies assemblies using the add assemblies button
- Tick the Sign with key file checkbox and select the strong name key file
- Now back to the package explorer, we want to replace the package’s assembly with the newly merged one and also change this new package’s metadata, to distinguish it from the original package
- we’re going to add a .Signed.Merged suffix to the name
- on the EDIT menu click Edit Metadata
- change only the Id field, by appending .Signed.Merged
- on the content drill down to the .dll and right click Replace with and select the newly merged assembly file
- save the package and you’ll see the file name is automatically updated
- Place the new package in your own package repository
- Add a reference to the new package from Visual Studio using the Manage NuGet references or the Package Manager console and you’re done!