I want to write a C# library for my MongoDB CRUD operations in Visual Studio 2019. And use this library later in different projects. I want to use the library in Blazor (.net core) and in WinForms (.net Framework). What project-type of "Class Library" do I have to choose? (I did try "library net Core" and "Winforms .net framework" -> didn't work)
Question 1: Is it project-type ".Net Standard Library"?
Question 2: How do I use/activate the Library in the Blazor Project? In Winforms, I right-click (References) and add the DLL to the WinformsProject, add an unsing statement and it works.
But in Blazor there is only Dependencies (no references). I did add "Project Reference" and choose the dll I could not get it to work. Do I need to add a COM Reference?
In short: How do I use a ClassLibrary is Blazor? What ClassLibrary type do I need? How can I then later use this Library in the Blazor Project (I guess this step needs to be explained step by step because I'm so noob)?
Thx for your Answer
I want to use the library in Blazor (.net core) and in WinForms (.net Framework).
It would be slightly easier and advisable to use WinForms on .NET core, which is now in a usable state. Much more future-proof.
Your options depend on your MongoDb access library (I assume you're not starting form scratch). It will probably support .net standard. .net standard is the common ground for .net 4.x and .net Core, so that is your best choice here.
I did add "Project Reference" and choose the dll I could not get it to work.
That is the way to go though. You didn't specify "could not get it to work", that would have helped.
But you won't be able to use this from Blazor Webassembly (client-side). You can only access this from Blazor server or a separate API server.
Do I need to add a COM Reference.
Absolutely not.
I guess this step needs to be explaint step by step
Add a ".net standard classlibrary" to your solution. Reference the MongoDb driver from this library, make sure it works. You probably want .net standard 2.0 or lower when you use WinForms on .net 4.x. standard 2.0 is the highest level for .net classic.
Then add references to this class lib from both your WinForms and Blazor (server) projects.