简体   繁体   中英

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?

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 .

You can do both - ie 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM