Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET (standard, Core and Framework): Developing Cross Platform Applications

I have searched SO, but I find a lot of answers but not targeting my questions:

AS the definitions say:

  • .NET Framework 4.6 is a full framework for everything related to .NET, but lacks libraries & runtime optimized for multi-platform (Windows, Linux and Mac) and cloud deployments
  • .NET Core on the other hand is a subset of .NET Framework 4.6 which is mainly optimized for multi-platform and cloud deployments
  • NET standard: a 'standard' set of APIs rather than a platform. So basically you don't care about platforms, just the standard (version 1.3, 1.6 ...) and your code will work on all platforms that support it.

In order to develop cross platform applications, I intend to create ASP.NET core applications (.NET) which might reference other class libraries that might use:

  • .NET Standard
  • .NET Core

I assume that if I use any(standard or Core) my application will still support other OS.

In Some cases, I see people using traditional .NET Framework With .NET Standard in class library?

  • In this case, Is the application still cross platform when using .NET Framework?
  • When Should I mix and use a combination (Standard , Core, NET)?
  • What is the best practices in using and mixing between frameworks?
  • How to avoid any conflicts and build failures?

For instance, let's say I have a class library that has the project.json:

 "dependencies": {
    "Microsoft.Extensions.Caching.Abstractions": "1.0.0",
    "Microsoft.Extensions.Options": "1.0.0",
    "StackExchange.Redis.StrongName": "1.1.608",
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.5": { }
  }

How is the dependency different from framework? and how is the project resolving the assemblies since the Standard Library is just a specification.

like image 374
Hussein Salman Avatar asked Oct 17 '22 23:10

Hussein Salman


1 Answers

In this case, Is the application still cross platform when using .NET Framework?

Not really, a .Net Framework application won't run on .Net Core. But it might run on mono, which is available on Linux and Mac OS.

When Should I mix and use a combination (Standard , Core, NET)?

You should use .Net Standard for your libraries, if you can (i.e. as long as they don't have any framework-specific dependencies).

You use .Net Framework for your applications if they have .Net Framework-specific dependencies or if the application can be Windows-only.

You use .Net Core for your application if it needs to be cross-platform, or if you want to use newest APIs. (.Net Core generally updates faster then .Net Framework and also has preview versions.)

What is the best practices in using and mixing between frameworks?

I don't understand the question. You can't mix .Net Framework and .Net Core in the same application.

How to avoid any conflicts and build failures?

I don't think that's an answerable question, though I can offer some obvious advice:

  • Read and follow the documentation.
  • Don't use unstable technologies. (Keep in mind .Net Core tooling is currently still in preview.)

EDIT:

How is the dependency different from framework?

"frameworks": { "netstandard1.5": { } } means that the library is a .Net Standard 1.5 library and decides which frameworks it can be used from.

"dependencies": { "NETStandard.Library": "1.6.0" } actually brings in the packages that are part of .Net Standard Library. It also means that the library can access all of .Net Standard Library, not just some subset of it.

How is the project resolving the assemblies since the Standard Library is just a specification?

The packages that NETStandard.Library depends on are more than just a specification. For example, the package System.IO.Compression.ZipFile contains:

  • reference assemblies used for compilation (i.e. the specification)
  • implementation of ZipFile for .Net Framework 4.6, which just forwards to the System.IO.Compression.FileSystem framework assembly
  • implementation for .Net Core which actually implements ZipFile

(To look inside packages yourself, I recommend NuGetPackageExplorer.)

like image 139
svick Avatar answered Nov 03 '22 01:11

svick