I want to develop a small library which will be used across different C# projects.
I was looking at this guide - https://github.com/LRPalacios/net-core-get-started
It talks about creating a Class Library (.NET Core).
However, my copy Visual Studio Community 2015 does not show this option at all.
Only relevant thing I see is Windows Desktop -> Classic Desktop -> Class Library .
What is the difference and what is the best way to create a class library for use across different C# projects. My library won't have any UI elements.
Also, is dll the only way to go - is there a concept of static libs in dotnet?
To fix the .Net core project type issue, you have to install Visual Studio Update 3 and then install .Net Core Tools for Visual Studio.
You can of course use the current Class Library project but this will work only against the Full .Net framework project not .Net core alone
Related
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.
I need to reuse the code of one library of CoreFX published at https://github.com/dotnet/corefx into one of my Winforms project.
For example, i need to use System.IO.Compression.ZipFile from https://github.com/dotnet/corefx/tree/master/src/System.IO.Compression.ZipFile
I dont't know if is possible reuse that code to implemt it at my .Net Framework Winforms app. If it can be done, i don't know how to do it. I don't want to create extra dlls, will be good reuse the code into the prject.
I tryed to download the source and place it inside a folder of my project but it did'nt work. I'm using Visual Studio 2015 and i'm kinda newbie managin C# projects.
I have a Visual Studio (2017) solution containing several C# ASP.NET Web Application projects (WebForms) targeting the 4.x .NET Framework. I am developing a class library that all of the ASP.NET projects can use, to avoid duplicating similar logic across multiple ASP.NET projects. The class library also needs to target the 4.x .NET Framework.
When attempting to create a new class library project, I see that the Windows Desktop Class Library (.NET Framework) project template allows me to choose the specific 4.x version I need.
But conceptually, linking a "Windows Desktop" Class Library in an ASP.NET project sounds odd to me.
My question is this: Is it safe/prudent/appropriate to use the "Windows Desktop Class Library" template for a class library that will be used by ASP.NET web application projects? Or is there some other more appropriate template or approach that would better suit this situation?
Yes, "Windows Desktop" -> "Class Library" is the right type of a project for a library to use with ASP.Net/ASP.Net MVC sites.
"Windows Desktop" is essentially "regular .Net as it was started in 2000" as opposing to Core, Standard or UWP variants. "Web" is grouping by type of project and somewhat confusing to be on the same level as variants of .Net… but that is how VS folks decided to group templates together.
I have a WPF application that uses a F# library for calculations. I'm trying to refactor so that I have WPF Application -> C# Portable Class Library (models) -> F# Portable Class Library (calculations).
My end goal is to use Xamarin Forms to put a UI on it that I can use on other platforms. This is currently mostly an experiment to assess the viability of the approach.
Every time I try to add a reference to the F# library from the C# library, I get an error message that says "Unable to add reference to X, Portable class libraries can only reference other portable class libraries".
I can reference either library from the WPF project and I've tried every permutation that I can think of to make it work.
There are quite a few similar questions, but they either don't have an answer or state that it is fixed in VS 2013. It doesn't seem to work in VS 2015 Update 2.
Does anyone have a link to a sample that works, or a workaround to get past the problem?
Steps for VS 2015 Update 2:
Create new(tested with new solution) Class Library (Portable)
As target choose only Windows 10 or Windows 8.1(maybe other target would work too - haven't tested though)
Add F# Portable Library(tested with .Net 4.5, Windows Store, Xamarin
and with .Net 4.5, Windows Store, Silverlight 5, Xamarin)
Now you can reference F# library without any errors
Now You can change properties of C# project(Right click on c# project and
choose properties) to match the targets You would like to have (Section Library, subsection Targeting)
Forgive if I am being incredibly dim, but how can I create a class library in Visual Studio that targets asp.net 4.5? As it stands, every time I add a new class library it defaults to DNX 1.0.0-beta5, which I don't want to use
For illustration purposes:
I create the initial MVC project targeting 4.5, which works absolutely fine
I then add a class library, again targeting 4.5
I then go look at it, and it's using .net 5 beta 5/DNX
If you go to the top level of C# templates instead of C#/Node, you will see three different Class Library templates: "Class Library (Package)", "Class Library (Portable)", and just plain "Class Library." Choose "Class Library."
The Class Library (Package) template is intended for creating Nuget Packages. I will pass along the feedback that this is causing confusion.