<TargetFramework> 和有什么区别?和<RuntimeFrameworkVersion>?

What#39;s the difference between lt;TargetFrameworkgt; and lt;RuntimeFrameworkVersiongt;?(lt;TargetFrameworkgt; 和有什么区别?和lt;RuntimeFrameworkVersiongt;?)
本文介绍了<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;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)