如何定位特定的 .NET 核心版本

How do I target a specific .NET core version

在我的开发机器上,我安装了 .NET 核心 5.0.5、5.0.6 和 5.07 托管包。 在我的生产机器上,我有 .NET 核心 5.0.5

在我的 .csproj 文件中我有:

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeFrameworkVersion>5.0.5</RuntimeFrameworkVersion>
    <Version>1.0.0</Version>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
    <OutputType>WinExe</OutputType>
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  </PropertyGroup>

我使用 VS2019 构建。

部署到生产环境后,我在事件查看器中得到以下信息:

Could not find 'aspnetcorev2_inprocess.dll'. Exception message:
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '5.0.7' was not found.
  - The following frameworks were found:
      2.1.15 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      3.1.1 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      5.0.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

显然我不想用5.0.7 我做错了什么?

将您的应用程序发布为自包含 会生成特定于平台的可执行文件。

通过这种方式,您可以控制与您的应用程序一起部署的 .NET 的版本

  • 您可以在下面查看更详细的解释。

错误已在 .NET5 中得到确认,据说将在 .NET6 中得到修复 https://github.com/dotnet/aspnetcore/issues/33941