What .NET Framework and C# version should I target

2019-02-03 18:14发布

I'm building a DLL class library - I want to make it usable by as many people as possible. Which version of the .NET Framework and which C# version should I use? Is it possible to produce a backwards-compatible DLL or different DLLs for different versions? Or does Windows automatically update the .NET framework so I should just use the latest version? Any guidance appreciated!

标签: c# .net dll build
12条回答
▲ chillily
2楼-- · 2019-02-03 18:29

try this:

switch targetting mode to framework 2.0 (removing System.Core reference).

if it not compile, than try adding a reference to linqbridge.dll:

If not, then you should target 3.5 ;)

查看更多
乱世女痞
3楼-- · 2019-02-03 18:30

Combined with using an approach like the one mentioned by Will Hughes, if you want the access / option to use newer features when available, during active development, use the latest framework. When ready to start making release candidates, set to the lowest framework, and then when issues arrive, steadily bump up the framework version and / or use the #ifdef approach to work out.

查看更多
闹够了就滚
4楼-- · 2019-02-03 18:31

I don't think anyone uses .Net 1.1 anymore. So unless you really want to use 3.5 features 2.0 should be fine. Also if you have control over who's going to actually use your library then it depends on them too. If they have the latest framework then you could use that.

查看更多
混吃等死
5楼-- · 2019-02-03 18:32

I vote for Erik van Brakel's answer. Also I would like to suggest that if you want to support 3.5 features like LINQ and Extension methods, you may create an additional library, say

MyLibrary.DLL

MyLibrary.LINQ.dll

thus using the same approach as MS did (when they left System.dll 2.0 version but added all new features into System.Core.dll)

查看更多
时光不老,我们不散
6楼-- · 2019-02-03 18:33

It depends on what the dll is for. If it just has a generic C# logic that you would like to make available to others, then .net 2.0 is probably your best bet. However if it has anything to do with the newer features in .net like WPF, EF, WCF, silverlight, ect then it will need to be in the version of .net that supports that particular feature.

Personally, I would say write it in .net 3.5 only because making the jump from .net2.0 to .net3.5 is pretty painless because there is not many breaking changes unlike the jump from .net1.x to .net2.0. :)

查看更多
▲ chillily
7楼-- · 2019-02-03 18:39

I would target version 2.0 with the library containing the core functions and add an extra library targeting 3.5 to add some extension methods based on your core library.

查看更多
登录 后发表回答