<TargetFramework> 和有什么区别?和 <RuntimeFrameworkVersion>? [英] What's the difference between <TargetFramework> and <RuntimeFrameworkVersion>?

查看:36
本文介绍了<TargetFramework> 和有什么区别?和 <RuntimeFrameworkVersion>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 来解决依赖关系并确定要用于编译和构建应用程序的资产.(在幕后,还有一些属性,如 TargetFrameworkMonikerTargetFrameworkVersion 开始发挥作用,但 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.App2.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 the 1.0.5 runtime installed, the 1.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 the DiaSymReader component.

      在 .NET Core 2.0 中,RuntimeFrameworkVersion 的版本将始终是 2.0.0 用于便携式应用程序"(非自包含),因为框架的实现不再由 Microsoft.NETCore.App 的依赖项提供,此 NuGet 包仅用于提供编译参考程序集.

      In .NET Core 2.0, the version of RuntimeFrameworkVersion will always be 2.0.0 for "portable applications" (non-self contained) because the implementation of the framework is no longer provided by the dependencies of Microsoft.NETCore.App and this NuGet package is only used to provide reference assemblies for compilation.

      这篇关于&lt;TargetFramework&gt; 和有什么区别?和 &lt;RuntimeFrameworkVersion&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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