我可以使用仅面向 .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
.