I have a project that targets two different operating systems/frameworks:
net461
on Windows and netcoreapp2.0
on OSXI'm trying to figure out how to correctly package this for NuGet. According to this post I should be able to package them like this:
/runtimes/win/lib/net461/myassembly.dll /runtimes/osx/lib/netcoreapp2.0/myassembly.dll
By when I add the NuGet package to another project, the packaged assemblies aren't added as references to the target project.
Then I read somewhere that you also need to add reference libraries to the /ref
folder so I tried this:
/runtimes/win/lib/net461/myassembly.dll /runtimes/osx/lib/netcoreapp2.0/myassembly.dll /ref/net461/myassembly.dll /ref/netcoreapp2.0/myassembly.dll
In this case the assemblies get added as a reference to the target project and I can build it, but the required assemblies aren't copied to the output folder.
The documentation on all this is extremely vague and I'm fairly lost.
What am I missing?
Associated NuGet Issue: https://github.com/NuGet/Home/issues/7316
Update: I've put together a sample project that demonstrates what I'm trying to achieve. In particular see the bottom of the readme, titled "NuGet Packaging".
The location of the default global packages folder. The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux).
Yes, the . nuget folder is used as a cache for packages downloaded to speed up project restore and compilation. It can safely be removed.
This is what I've finally figured out/guessed (because as best I can tell there's no official documentation for some of this)
Putting this all together, my original example, should have looked like this:
/lib/net461/myassembly.dll (net461/Windows Compile and Runtime) /runtimes/osx/lib/netcoreapp2.0/myassembly.dll (netcore/OSX Runtime) /runtimes/win/lib/netcoreapp2.0/myassembly.dll (netcore/Win Runtime) /ref/netcoreapp2.0/myassembly.dll (netcore/* Compile Time)
I spent a fair amount of time trying your project on OSX in both Visual Studio for Mac and VS Code. I'll try to stick with factual observations without getting into "why don't you do X instead".
runtimes/{rid}/lib/{tfm}/*.dll
paths look oktarget="lib/{tfm}/..."
assemblies are automatically referenced, runtimes/...
are notnetstandard
seems like it would make your package work in both netcoreapp
and netstandard
projects (e.g. use target="lib/netstandard1.6/..."
). Compare with this runtimes/
seems to be intended for platform-dependent assemblies you'll load at runtime. For example, 32/64-bit native assemblies in runtimes/win-x64/native/
and runtimes/win-x86/native/
) loaded with AssemblyLoadContext
(another post by McMaster)target="ref/..."
, but you can add Explicit Assembly <references>
(inside the nuspec <metadata>
block)dotnet publish
they'll be included:If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With