3

Everyone seems talking easy about it but I don't get it.

.NET Standards is a subset of functionalities of every .NET frameworks that you have to follow if you want to make your framework .NET Standard compliant and so compatible on all the platforms .NET can target.

Then why I have to specify manually "netstandard20", "net461" and so on in targetframework?

Shouldn't it be compatible with everyone?

What's even the sense of targenting himself "netstandard20"?

  • What's a "w/e?" – Robert Harvey Jan 12 '18 at 17:37
  • @RobertHarvey Whatever – Liquid Core Jan 12 '18 at 17:54
  • 8
    Please avoid the use of txtspk in your posts. This is a website for industry professionals; it's not Facebook or Twitter. – Robert Harvey Jan 12 '18 at 17:59
  • 5
    Good. Professionals use the English language in a professional way to communicate with other professionals. Reserve txtspk for when you are texting. – Robert Harvey Jan 12 '18 at 18:04
  • 5
    Only on cell phones. This isn't controversial; survey after survey shows that even millennials dislike txtspk in professional discourse. It's considered amateurish. Go ahead and use it if you must; just don't expect your peers to take you seriously. – Robert Harvey Jan 12 '18 at 18:08
2

Specifying the target framework has everything to do with where you intend to deploy your application and what C# features you intend to use. The more specific answer to any project is specific to that project.

The trade-off for using the latest and greatest version of .Net is that you trade compatibility for convenience. That's also part of the reason for the NetStandard suite.

  • Net Standard works well for libraries since it will be compatible with multiple deployment targets
  • Your application itself needs to be targeted for a normal platform (.Net 4.x, UWP, Silverlight, etc).

You can also check out the guidance on the GitHub project for Net Standard which enumerates the trade-off pretty well:

  • The higher the version, the more APIs are available to you.
  • The lower the version, the more platforms implement it.

You get to decide what's right for your project. Maintaining legacy code means staying on legacy versions of .Net, unfortunately. Which means those projects have to specifically target the older versions.

7

Visual Studio allows you to target different frameworks because some of us still have to support older operating systems or other software that does not use the newer frameworks. If you doubt the veracity of this statement, just do a Google search for Internet Explorer 6, and bask in the hate of the people who still must support it in some way because their clients are unable or unwilling to upgrade their Model T.

It's incredibly useful for your IDE to be able to tell you "You can't use that keyword or method overload, because it doesn't exist in .NET 3.5."

  • I already knew that. I want the use case. What is the use case? Like: Hey this program is going to run on Win XP so it's gonna use only .NET 3.5 and backwards. Let's say the compiler this is "net35" targetframework so you can't use newer things that are only in .NET 4.7? I saw you can specify also multiple targetframework, like "net452, netcore, netstandard". What about that? – Liquid Core Jan 12 '18 at 18:04
  • 2
    Hey this program is going to run on Win XP so it's gonna use only .NET 3.5 and backwards. Let's say the compiler this is "net35" targetframework so you can't use newer things that are only in .NET 4.7? -- Yes, exactly. – Robert Harvey Jan 12 '18 at 18:05
  • Ok. Could you give me hints on "TargetFrameworks" too? How the compiler is going to recognize one or another in that case? – Liquid Core Jan 12 '18 at 18:07
  • I don't know what you mean. – Robert Harvey Jan 12 '18 at 18:07
  • I am also unsure what you mean, it's not clear from the way you phrased the question. Are you talking about the ability to specify multiple target frameworks that you mentioned earlier? If so, see this. (In short, the build system uses predefined preprocessor symbols.) – Filip Milovanović Jan 12 '18 at 18:44
2

Also,

.NET Standard has multiple versions, which are not necessarily compatible with every framework. (netstandard2.0 is not compatible with net450).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.