Michael C Michael C - 23 days ago 5
C# Question

Sharing a DLL between projects

Going slightly insane on this one, spent a whole afternoon so far. Learned a lot but not what I'm looking for.

Microsoft says it's platform neutral these days, so I'm trying to build on Mac and Linux only with VS Code and deploy to Azure. Why? It's mainly to prove that I can rather than because I have anything against Windows. I'm a 20+ year veteran of Windows development, I have nothing against it at all. I think I just like Mac hardware more and if I can have that and keep using my favourite language, why not! Anyway...
Our project has several parts which include a couple of different websites, a Web API, er API and a few other bits. On my Mac I've built a .Net Core Class Library with a load of objects in. Command line, dotnet build, DLL out, no problem. Happy days.

I want to put that DLL on the Linux machine where the MVC website is being built - the objects forming the models part of that site hopefully. For the life of me I cannot figure out how to get the website project to reference my DLL and use the objects.
I had (foolishly) assumed I copy it to the other machine, place it in the bin folder of the site being developed and reference it in the Dependencies section of the site's project.json. Nope. After several scary hours of reading I saw a few articles that said .Net Core only works with NuGet and it had to be a package. Is that really true?

I've found and read (if not entirely understood) everything you could imagine on sharing between .net core and .net framework. This is a core-only project so not applicable. Frankly I'm lost, and something called .Net Standard has just rolled into my field of vision so I reckon it's time for a Gin. "The Internet" (Google and links to this site) has a 100% record of knowing the answer so far, in everything I've ever struggled with. I thank you in advance for shedding light into the vast darkness of my world!


So instead of copying the DLL, use dotnet pack to build a nuget package on your Mac, and copy that to your Linux machine instead. Put it in a directory that you configure as a local nuget repository (no server or anything required) and you're away.

I agree it's not as straightforward as a reference to a DLL, but it's not too bad. Note that you'll need to version the package appropriately, so that the tool system can detect when it's changed.