问题描述
我听说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": { }
}
之所以有效,是因为包同时具有.NET Framework 4.5.1和.NET Standard Library 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"
}
}
}
}
在这种情况下,请注意<$ c将$ c> 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!