简体   繁体   English

提示用户安装正确 dotnet 版本的错误信息不正确

[英]The error message that prompts user to install the correct dotnet version is incorrect

I have created a Windows form project and targeted .NET 4.5我创建了一个 Windows 表单项目并针对 .NET 4.5

在此处输入图片说明

When I run the exe file on a machine that does not have .NET 4.0 installed, I get the following error message:当我在没有安装 .NET 4.0 的机器上运行 exe 文件时,我收到以下错误消息:

在此处输入图片说明

When I install .Net 4.0 and run the exe again I get the following error message:当我安装 .Net 4.0 并再次运行 exe 时,我收到以下错误消息:

在此处输入图片说明

Why the first message is not stating that the required .NET version is 4.5??为什么第一条消息没有说明所需的 .NET 版本是 4.5??

According to this article , the version of the .NET Framework that an application runs on is determined in the following order:根据本文,应用程序运行的 .NET Framework 版本按以下顺序确定:

  1. Configuration file ( .config )配置文件 ( .config )
  2. Compiled version编译版本
  3. Latest version installed已安装最新版本

By default if you set the target framework in Visual Studio you have a .config file that you deploy alongside your .exe .默认情况下,如果您在 Visual Studio 中设置目标框架,您将拥有一个与.exe一起部署的.config文件。 In this .config file Visual Studio creates an element <supportedRuntime> which has two attributes: version and sku在这个.config文件中,Visual Studio 创建了一个元素<supportedRuntime> ,它有两个属性: versionsku

The default element for .NET 4.5 looks like this: .NET 4.5 的默认元素如下所示:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

version is the version of the supported CLR - but that's not necessarily the same as the version of the .NET Framework because all of the .NET Frameworks from 4.0 to 4.7 are using the CLR 4.0. version是受支持的 CLR 的版本 - 但这不一定与 .NET Framework 的版本相同,因为从 4.0 到 4.7 的所有 .NET Framework 都使用 CLR 4.0。
Only sku (stock-keeping unit) specifies the exact release of the .NET Framework that your application supports.只有sku (库存单位)指定您的应用程序支持的 .NET Framework 的确切版本。

According to this article , the sku attribute (containing a version number) is only being recognized starting with the .NET Framework 4.0.根据本文sku属性(包含版本号)仅从 .NET Framework 4.0 开始被识别。

As a side note: .NET 3.5 has used the sku as well but only to specify that you are supporting the .NET Framework Client Profile ( sku="client" ) which doesn't exist any longer since .NET 4.5.附带说明:.NET 3.5 也使用了sku ,但只是为了指定您支持.NET Framework Client Profile ( sku="client" ),该配置文件自 .NET 4.5 起不再存在。

So the conclusion is:所以结论是:
You are getting the first error message because the CLR 2.0 loader in the .NET Framework 3.5 doesn't know anything about the sku attribute.您收到第一条错误消息是因为 .NET Framework 3.5 中的 CLR 2.0 加载程序对sku属性一无所知。 It only knows that you are requesting a .NET 4.0 CLR.它只知道您正在请求 .NET 4.0 CLR。 (If you don't have a .config file the required version of the CLR is compiled into the manifest of your .exe , which in your case is v4.0.30319 .) (如果您没有.config文件,则所需版本的 CLR 将编译您的.exe清单中,在您的情况下为v4.0.30319 。)

Only after installing the .NET Framework 4.0 the CLR 4.0 loader now reads the sku attribute and therefore knows that you also have to install the .NET Framework 4.5.只有在安装 .NET Framework 4.0 之后,CLR 4.0 加载程序才会读取sku属性,因此知道您还必须安装 .NET Framework 4.5。 That's why you're getting this two error messages.这就是您收到这两条错误消息的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM