我可以使用仅面向 .NET 4.6.1 的 ASP.NET Core 吗? [英] Can I use ASP.NET Core targeting only .NET 4.6.1?

查看:25
本文介绍了我可以使用仅面向 .NET 4.6.1 的 ASP.NET Core 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说 ASP.NET Core 可以针对 .NET Framework 4.6.1.这是否意味着它只能使用 .NET 4.6.1,还是可以将 .NET 4.6.1 与 .NET Core 一起使用?

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?

推荐答案

您可以在 .NET Core 1.0 或 .NET Framework 4.5.1+ 之上运行 ASP.NET Core.由于ASP.NET Core"实际上只是一组 NuGet 包,您可以将它们安装到面向任一框架的项目中.

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.

例如,.NET Core 项目如下所示:

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": { }
  }

虽然 .NET Framework 项目看起来像(在 .NET 4.6.1 的情况下):

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": { }
  }

之所以有效,是因为 Microsoft.AspNetCore.Mvc 包具有针对 .NET Framework 4.5 的目标.1 和 .NET 标准库 1.6.

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"
        }
      }
    }
  }

在这种情况下,请注意 Microsoft.NETCore.App 依赖项被移动到 frameworks 部分的内部.这是必要的,因为只有在为 netcoreapp1.0 而不是 net461 构建时才需要此依赖项.

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.

这篇关于我可以使用仅面向 .NET 4.6.1 的 ASP.NET Core 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆