Does MEF require .NET 4? - c#

I am using Visual Studio 2010, try to create a MEF application. Does this require .NET 4.0 or can I target .NET 2.0?

Yes you do:
Application requirements change
frequently and software is constantly
evolving. As a result, such
applications often become monolithic
making it difficult to add new
functionality. The Managed
Extensibility Framework (MEF) is a new
library in .NET Framework 4.0 that
addresses this problem by simplifying
the design of extensible applications
and components.
From:
http://mef.codeplex.com/
Edit:
The question about targeting .net 2.0 is answered here:
http://mef.codeplex.com/Thread/View.aspx?ThreadId=54008
MEF is not supported on .NET 2.0 as it
depends on LINQ and Expression trees.
Currently we do not have a .NET 2.0
version of MEF planned.

Strictly speaking you don't have to have .Net 4.0 installed. You can use MEF with .Net 3.5 - if you reference System.ComponentModel.Composition.dll.
As DannyLane says, however, you do need the LINQ functionality so you can't target .Net 2.0.

Related

How to decide .net framework versions to create a library [duplicate]

This question already has answers here:
What is the difference between .NET Core and .NET Standard Class Library project types?
(13 answers)
Closed 3 years ago.
I want to create a library to use in .Net framework applications and Xamarin applications. But there are 3 framework versions:
.net core
.net framework
.net standart
So I could not decide which version to use my common library.
If I create a .net standart library, does it work in .net framework and .net core.
If I create a .net core library, does it work in .net framework and .net standart.
I am confused about frameworks.
This might help you decide
.Net Standard : Used for building libraries that can be referenced from all .NET implementations, such as .NET Framework, .NET Core and Xamarin
.Net Core : Used for building cross-platform console apps and ASP.NET Core Web apps and cloud services.
So when if you want your library to be supported by all different type of .Net implementations, .Net standard is the way to go.
As you're writing a C# library I imagine you know the difference between a class and an interface. A class is a concrete implementation of some feature set, and an interface defines what features you can expect from an instance that implements it.
Using this as an example, .NET Framework and .NET Core are like classes. .NET Framework is the "classic" implementation, and .NET Core is a newer implementation which has advantages such as being able to run on Linux. If you build a library to target .NET Core or .NET Framework, you are building it to target one of those concrete implementations.
.NET Standard on the other hand is like an interface. Each version of .NET Standard provides a set of features, and different versions of .NET Framework/.NET Core implement different versions of .NET Standard. When you build a library that targets a given version of .NET Standard, you're saying that you can support all of the concrete implementations in the corresponding column of that table.
Deciding what version of .NET Standard to target will depend on what functionality you need to implement your library. More features usually means a higher version and supporting fewer implementations. Fewer features means a lower version and more widespread support.
So many confusing other answers here.
First and foremost it depends on what platforms you are targeting.
is it a generic use library you want share with the world?
is it an application specific library (i.e. reusable code for the same application, i.e. a line of business application) which is to be used on multiple platforms
Case 1
You should go with .NET Standard, since it gives you the most platforms. Which version you use, depends on the features you need.
If you want reach the most platforms, try to target as low as possible (.NET Standard 1.0, it targets .NET Core 1.0, .NET Framework 4.5, Mono, Xamarin iOS 10/Mac 3.0/Android 7.0, UWP 10 and Uniy 2018.1 and all newer versions of these).
You can see the exact .NET Standard Matrix in the provided link.
If you need specific API you have to target a higher version, such as .NET Standard 2.0 which a lot (~22k new APIs from .NET Framework have been ported to .NET Core 2.0 from 1.1) APIs than .NET Standard 1.1.
This may not allow you all APIs (no WPF/WinForm specific apis) but in generic use reusable libraries this shouldn't be an issue.
Case 2
Here, you can also apply Case 1 tips, if possible.
If that doesn't cover your required Apis and you know you don't want target .NET Core or Unity, you can still use the old styled PCLs: Portable Class Library.
They are a more complicated versions of .NET Standard (kinda a predecessor of .NET Standard), where depending on which platform you target the API surface shrinks to only allow APIs to be used which run on all these platforms.
It's not recommended these days to use PCLs, since .NET Standard is preferred and more easy (for library authors) to use and target multiple platforms.
Last but not least, if you really need some feature only on Windows and .NET Framework (or you don't care for .NET Core), you can still cross-target, i.e. have a .NET Standard 2.0 for all platforms and add specific APIs only to net45 target and preprocessor instructions (#if NET45/#endif).
This compiles into two libraries, one for netstandard2.0 and one for net45 (.NET Framework 4.5).

Reference a .NET Core 3.0 library in .NET 4.8?

I have been trying to follow some already existing tutorials and stackoverflow questions/answers, but nothing seems to be working;
Reference a .NET Core Library in a .NET 4.6 project
Referencing .NET Core library in .NET 4.5.2
https://www.youtube.com/watch?v=qc2WFaMfdp8
I am working in Visual Studio 2019 V16.0.0 Preview 2.2, if that is relevant.
As mentioned by Marc Gravell, .NET Core and .NET Framework are different frameworks. The Api Surface that each of them offer is different. A good way to picture their surface area is by using a Venn Diagram, where the intersection of both is what we call .NET Standard. If the library you are consuming was targeting .NET Standard, then this would be guaranteed to work in both .NET Framework 4.8 and in .NET Core 2.1+. You can try consuming a .NET Core 3.0 library in a .NET Framework app but that is not guaranteed to work, as you might get lucky and your .NET Core library only needs the API surface that they have in common, but most likely it will need something that is only supported in .NET Core 3.0 which will mean that you will get Runtime Exceptions for methods not found, types not found, or assembly load issues.
Do you own the .NET Core Library code? If so, the best option for you would be to try to retarget to .NET Standard (so that you can use the library in the future in other frameworks) or .NET Framework directly, and that way you would know that all of the API surface your library needs will be present at runtime.
I hope this helps clarifying the issue, but feel free to reply in case you want more details.

Are C# and .NET versions dependent on each other?

I'm just starting to learn C# and its relationship to .NET. If say I wanted to take advantage of the latest C# language conventions, but wanted to target, say a .NET 2.0 framework, could I do that? Or does using the latest C# mean I have to use the latest .NET?
C# as a language is not dependent on .net framework.
For example: Extension methods is a feature released with C# 3.0 which came along with .Net 2.0.
Extension methods depends on ExtensionAttribute which lives in "mscorlib.dll" which was added in .Net 3.5. But you can use Extension methods in .Net 2.0 given that you provide your own ExtensionAttribute in your library itself. It doesn't needs to be in mscorlib. Refer this question for more info.
As we know async-await is new in C# 5.0 which was released with .Net 4.5, but we can use async-await in .Net 4.0 itself.
Sameway, most of the dependencies of language features can be defined in your own assembly to make it work. So it doesn't need the particular .Net framework version.
you can use features of lastest visual studio editions (2013, 2015), but the code must be according to 2.0 specifications to allow a .NET 2.0 compilation (older versions)
Yes, C# and .Net versions are dependent. According to my understanding C# is a programming language which works using .Net Technology.
Learning C# means learning the basic syntax, which is almost the same in all .Net versions. So for learn c#, it doesn't matter which .Net version you must target. Different .Net versions adds up certain new features or functionality. Any way its better to understand latest .Net version which will help you in projects.
You can use C# features from earlier versions with later versions of .Net, for example, you can use any C# 2.0 feature with .Net 3.5, this does not work the other way arround, so you cannot use .Net 3.5 features with the c# 2.0 compiler.
For more details see: https://msdn.microsoft.com/en-us/library/ff602939(v=vs.110).aspx
C# 6.0 is available in .NET 5.0.
It depends on the CLR. C# 4, 4.5 and 4.5.1 are using the CLR Version 4.
Yes C# is dependent on .net versions. The dependence between the both is on features and technologies provided. Refer following link:
https://msdn.microsoft.com/en-us/library/bb822049%28v=vs.110%29.aspx

Using .NET 1.1 libraries in .NET 4.0 applications

Are there any known stability issues when using .NET 1.1 libraries in a .NET 4.0 application?
We have used many .NET 1.0 libraries in different version of framework (any thing between 1.1 to 4.0) and have never experienced any issues. we currently use SQLDataProvider which I think was release a bit after .NET 1.0.
Then again it all depends on the code that is included in those libraries. I would spend some time to look for updated version of those libraries or even alternative, specially something that was written in 2.0 or higher just because of introduction of generics.
but otherwise, do some testing and you should be fine.
Generic answer is NO. You should be able to use .NET 1.1 libraries in a .NET 4.0 project witout any issues. But every library is different. Is it a custom dll? Does it use any COM components?

How and where to learn the changes in .net from .net 2.0 to .net 3.5?

I left the .net about 3 years back when I was working on .net 2.0. And in these three years I wasn't working on .net at all. Now, I have got a project which is in .net 3.5. But I have noticed there are a lot of technologies introduced between these two versions.
Is there any resource which can help me to quickly grasp the things which are introduced after .net 2.0
It may help that my major work is in asp.net with C#
For a quick overview ...
What's New in .NET Framework 3.5 (taken from here)
CLR Enhancements: Although the CLR uses the same model as 2.0, you can read here about the improvements/changes to the assemblies.
Compiler Enhancements: New VB.NET 9.0 compiler and support for changes to C# 3.0 like expression trees, lambda methods, extension methods, static reference for anonymous types etc.
LINQ: Probably the most revolutionary change in the 3.5 framework. LINQ to XML, LINQ to SQL, LINQ to Objects and LINQ to Datasets. Along with functional programming, LINQ is an outlook change to programming in C#.
Performance Improvements: Quite a few performance improvements have been made in 3.5. ADO.NET gets paging support as well as synchronization from caches at local and server datastores. Also performance improvements for multicore CPUs.
Networking changes: Peer-to-peer networking stack, including a managed PNRP resolver.
Windows Information APIs: New wrappers for WMI and Active Directory Services. WMI 2.0 gets a managed provider.
ASP.NET: New implementation of Client Application Services as well as 3 new ASP.NET controls. Also AJAX programming for ASP.NET is easier and better performing.
Windows Communication Foundation: WCF now works with POX and JSON data.
Windows Presentation Foundation: Newer plugin model for creating AddIns. SilverLight CLR is also part of the .Net Framework.
Misc: The C/C++ get a standard template libarary (STL) so that these languages can use share .NET libraries
for some extra reading ...
What's New in the .NET Framework Version 3.5 SP1
What's New in the .NET Framework Version 3.5
What's New in the .NET Framework Version 3.0
What's New in the .NET Framework Version 2.0
What's New in the .NET Framework Version 1.1
Version Compatibility
What's New in the .NET Compact Framework Version 3.5
What's New in ASP.NET and Web Development
What's New in Visual C#
What's New in Visual C++ 2008
What's New in the Visual Basic Language
What's New in Windows Presentation Foundation Version 3.5
What's New in Visual Studio 2008
What's new in the .NET Framework 3.5
I've just bought this book for the same purpose myself:
C# in Depth: What you need to master C# 2 and 3 by Jon Skeet. I consider it a good start.
This is a good start:
What's New in the .NET Framework Version 3.5
http://msdn.microsoft.com/en-us/library/bb332048.aspx
Also see What's new in the .NET Framework 3.0.

Categories

Resources