Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use ASP.NET Core targeting only .NET 4.6.1?

I heard that ASP.NET Core can target .NET Framework 4.6.1. Does that mean it can use only .NET 4.6.1, or it can use .NET 4.6.1 alongside with .NET Core?

like image 225
Hoang Hiep Avatar asked Jul 03 '16 04:07

Hoang Hiep


People also ask

Which .NET framework should I target?

I would recommend moving to the . Net 4.0 Client Profile. Although it doesn't have a large install base yet, it's a small download that your users can easily install. If you don't want your users to need to download the framework, you should target 3.5, which most people already have.

Is .NET 4.6 still supported?

NET Framework 4.6, which shipped in Windows 10 Enterprise LTSC 2015. We will continue to support . NET Framework 4.6 on Windows 10 Enterprise LTSC 2015 through end of support of the OS version (October 2025).


2 Answers

You can run ASP.NET Core on top of .NET Core 1.0, or .NET Framework 4.5.1+. Since "ASP.NET Core" is really just a set of NuGet packages, you can install them into a project targeting either framework.

For example, a .NET Core project would look like this:

  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    }
  },
  "frameworks": {
    "netcoreapp1.0": { }
  }

While a .NET Framework project would look like (in the case of .NET 4.6.1):

  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.0"
  },
  "frameworks": {
    "net461": { }
  }

This works because the Microsoft.AspNetCore.Mvc package has targets for both .NET Framework 4.5.1 and .NET Standard Library 1.6.

It's also possible to build for both frameworks from one project:

  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.0",
  },
  "frameworks": {
    "net461": { },
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      }
    }
  }

In this case, note that the Microsoft.NETCore.App dependency is moved inside of the frameworks section. This is necessary because this dependency is only needed when building for netcoreapp1.0, not net461.

like image 196
Nate Barbettini Avatar answered Oct 14 '22 13:10

Nate Barbettini


You can do both - i.e. target only desktop CLR, Core CLR or both. To target desktop Clr 4.6.1 use the net461 moniker as target framework. To target Core Clr use netcoreapp1.0. You can use them side by side but it feels a bit awkward - why would you do even do that in case of apps?

like image 41
Pawel Avatar answered Oct 14 '22 12:10

Pawel