问题描述
我在 csproj
文件中有以下代码:
I have the following code in a csproj
file:
<TargetFramework>netcoreapp1.0</TargetFramework>
在 NuGet 包管理器中,它说我有 Microsoft.NETCore.App 1.0.5 版
In the NuGet package manager, it says that I have Microsoft.NETCore.App version 1.0.5
现在假设我在同一个 csproj
文件中有以下代码:
Now let's say I have the following code in the same csproj
file:
<TargetFramework>netcoreapp1.0</TargetFramework>
<RuntimeFrameworkVersion>1.1.4</RuntimeFrameworkVersion>
NuGet 包管理器现在会说我有 Microsoft.NETCore.App 1.1.4 版
The NuGet package manager will now say that I have Microsoft.NETCore.App version 1.1.4
我实际上是在尝试使用 .NETCore 2.0 之前的最新框架(转换时出现一些 EF 问题),即 .NETCore 1.1.4,但 csproj
中的多个框架属性使我不确定要使用哪个标签.我找不到任何可以清楚地区分两者之间差异的资源.
I'm essentially trying to use the latest framework before .NETCore 2.0 (having some EF issues when I converted) which would be .NETCore 1.1.4, but the multiple Framework attributes in csproj
make me unsure which tag to use. I was unable to find any resources that clearly distinguishes the differences between the two.
推荐答案
NuGet 使用 TargetFramework
来解决依赖关系并确定用于编译和构建应用程序的资产.(在幕后,TargetFrameworkMoniker
和 TargetFrameworkVersion
等更多属性开始发挥作用,但 SDK 将其抽象为更简单的 TargetFramework
以用于它知道的框架大约).
The TargetFramework
is used by NuGet to resolve dependencies and determine the assets to be used for compiling and building the application. (Behind the scenes, a few more properties like TargetFrameworkMoniker
and TargetFrameworkVersion
come into play but the SDK abstracts it to a simpler TargetFramework
for frameworks it knows about).
RuntimeFrameworkVersion
特定于 .NET Core/netcoreapp
.SDK 将为 RuntimeFrameworkVersion
设置的版本注入对 Microsoft.NETCore.App
的依赖项,或使用它所知道的 .NET Core 的最新版本 Microsoft.NETCore.App
2.0.然后将解析后的版本写入 .NET Core 主机框架解析器的 runtimeconfig.json
文件,以解析要加载的共享框架的版本(例如=> .NET Core 1.1.4 运行时).
The RuntimeFrameworkVersion
is specific to .NET Core / netcoreapp
. The SDK will inject a dependency on Microsoft.NETCore.App
for the version that RuntimeFrameworkVersion
is set to or use the latest version it knows about for .NET Core < 2.0. The resolved version is then written to the runtimeconfig.json
file for the .NET Core host framework resolver to resolve the version of the shared framework to load (=> .NET Core 1.1.4 runtime for example).
您能够将 1.1.*
用于 netcoreapp1.0
的原因是 NuGet 包实际上包含构建 .NET Core 1.0.* 应用程序所需的资产.但是工具不知道这一点,因此您将获得一个 .NET Core 1.0 应用程序,但它将由 1.1 框架加载,因为这最终会出现在 runtimeconfig.json
文件中.
The reason you are able to use 1.1.*
for netcoreapp1.0
is because the NuGet package actually contains the necessary assets to build .NET Core 1.0.* applications. However the tooling doesn't know this so you'll get a .NET Core 1.0 app but it will be loaded by the 1.1 framework because that's what ends up in the runtimeconfig.json
file.
重要的区别是:
- 仅对于使用哪个版本的
Microsoft.NETCore.App
的独立可执行文件很重要.- 此包将在执行自包含发布时引入具有所需版本的完整框架(例如
dotnet publish -r win7-x64
) - 当您运行为
1.0.3
构建的应用程序但安装了1.0.5
运行时,1.0.5
运行时将自动使用. - 如果您未设置
RuntimeFrameworkVersion
并且发布了了解 .NET Core 更新补丁版本的新版本 SDK,它将自动使用最新版本.如果您明确设置版本,则您可能无法在不编辑项目文件的情况下保持最新.
- It only matters for self-contained executables which version of
Microsoft.NETCore.App
is used.- This package will pull in the complete framework with the desired version when performing a self-contained publish (e.g.
dotnet publish -r win7-x64
) - When you run an application built for
1.0.3
but you have the1.0.5
runtime installed, the1.0.5
runtime will be used automatically. - If you don't set
RuntimeFrameworkVersion
and a new version of the SDK is released that knows about newer patch versions of .NET Core, it will use the newest version automatically. If you set the version explicitly, you may not be up-to-date without editing the project file.
除此之外,使用更高版本的
Microsoft.NETCore.App
构建只有几个原因,例如DiaSymReader
组件的构建错误修复.Apart from these, there are only a few reasons to build using a higher version of
Microsoft.NETCore.App
, like a build bugfix for theDiaSymReader
component.在 .NET Core 2.0 中,
RuntimeFrameworkVersion
的版本对于便携式应用程序"(非自包含)将始终为2.0.0
,因为框架的实现不再由Microsoft.NETCore.App
的依赖项提供,此 NuGet 包仅用于提供参考程序集进行编译.In .NET Core 2.0, the version of
RuntimeFrameworkVersion
will always be2.0.0
for "portable applications" (non-self contained) because the implementation of the framework is no longer provided by the dependencies ofMicrosoft.NETCore.App
and this NuGet package is only used to provide reference assemblies for compilation.这篇关于<TargetFramework> 和有什么区别?和<RuntimeFrameworkVersion>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
- This package will pull in the complete framework with the desired version when performing a self-contained publish (e.g.
- 此包将在执行自包含发布时引入具有所需版本的完整框架(例如