【问题标题】:A fatal error occurred. The required library hostfxr.dll could not be found发生致命错误。找不到所需的库 hostfxr.dll
【发布时间】:2021-11-02 21:27:07
【问题描述】:

当我在其他计算机上运行我的 WPF 应用程序时,它会抛出这个错误:

Description: A .NET Core application failed.
Application: program.exe
Path: C:\fakepath\program.exe
Message: A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in 
[C:\fakepath\].
If this is a framework-dependent application, install the runtime in the global location [C:\Program 
Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or 
register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].

添加库运行时 3.1.0 对我有帮助。

【问题讨论】:

  • 我在 Azure 上的测试项目中遇到了这个问题。我必须在管道的开头添加一个安装运行时的步骤。

标签: .net-core


【解决方案1】:

进一步 Ajith 的回答,“部署模式:自包含”也可以在此处的 Visual Studio 2019 中选择:

【讨论】:

  • 在我的情况下这样做会引发“System.PlatformNotSupportedException”
  • 我需要运行控制台应用程序 exe 另一台 Windows 10 机器,该机器不存在于 VS 2019 中发布的 .net 框架。但我无法运行它。发生同样的错误。我该怎么办?阿丹桑多瓦尔
  • 自给自足,奇怪的是,它自己并没有为我修好。如果您单击显示所有设置 -> 文件发布选项,我还必须检查“生成单个文件”和“启用 ReadyToRun 编译”,然后它就可以工作了。
  • @DanCsharpster - 是的,这也对我有用。但是 - 它为我的 30 行控制台应用程序创建了 60 MB 的 exe 文件。到目前为止,我一直在 Visual Studio 2008 中构建我的其他小型控制台应用程序,并且只获取了几个 KBs 文件。这真是一个惊喜......
  • @Marek,它将您可能需要运行它的所有库放入一个文件中。这并没有让我很惊讶,但很烦人。
【解决方案2】:

今天我的 .Net core 3.0 应用程序遇到了同样的错误。这是因为您缺少机器中的 .net 核心运行时,并且正在安装依赖于框架的应用程序。

解决方案是使用自包含部署模式发布应用程序。

使用下面的命令从命令行发布

dotnet publish -c Release -r <RID> --self-contained true

从https://docs.microsoft.com/en-us/dotnet/core/rid-catalog#windows-rids 获取 RID 详细信息

【讨论】:

  • 我正在使用msbuild 而不是dotnet publish 构建我的程序,你碰巧知道打开部署模式自包含的标志吗?
【解决方案3】:

我在依赖框架的应用程序中避免“hostfxr.dll 丢失”的解决方案是在目标计算机上安装“Hosting Bundle”。

ASP.NET Core 运行时使您能够运行现有的 Web/服务器应用程序。在 Windows 上,我们建议安装 Hosting Bundle,其中包括 .NET Core 运行时和 IIS 支持。

https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.9-windows-hosting-bundle-installer

【讨论】:

  • 在 2021 年,这是最简单、最简单的解决方案。
【解决方案4】:

从错误消息来看,如果这是framework-dependent application:

If this is a framework-dependent application, install the runtime in the global location [C:\Program 
Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or 
register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].

请将 DOTNET_ROOT 环境设置为以下位置之一,具体取决于您安装的位置dotnet.exe

C:\Program Files\dotnet OR C:\Program Files (x86)\dotnet

来自“我的电脑 | 属性 | 高级 | 环境变量”。现在重新启动您正在使用的 IDE/终端。

【讨论】:

  • 我已经浪费了一周的晚上试图解决 NUnit 无法正常工作的问题,希望我能给你 10 票。 Nunit 和 .NET Core 正在运行
【解决方案5】:

在寻找解决问题的方法时,我多次访问此页面。

我的独立 exe 引发了错误

Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.1

我正在发布 .net core 3.1 运行时并引用一个引用 System.Data.SqlClient, Version=4.6.1.1 的 netstandard 库

以下 git hub 页面将此标记为已知问题 https://github.com/dotnet/core/blob/master/release-notes/3.1/3.1-known-issues.md#net-core-312

将我们的 exe 设置为发布 .net core 3.0 运行时为我们解决了这个问题。 我们可以控制引用的库,因此可能会遵循 github 页面上的建议,但对于其他没有控制库的人来说,可能会发现这个有用。

【讨论】:

    【解决方案6】:

    由于某种奇怪的原因,.net 发布者未能发布自包含的 .Net Core 3 应用程序(控制台应用程序)。我已经解决了这个问题,只需在服务器上安装 .Net Core 3 Runtime。

    【讨论】:

      【解决方案7】:

      EntityFrameWork Core 已移出您需要全局安装依赖项的 dotnet sdk 检查 progr C:\Users"Your User Name".dotnet\tools.store\dotnet-ef\3.1.5 是否存在全局成功安装 EFcore 并确保您的项目级别的 Ef Core 依赖版本与全局安装的 EFcore 版本匹配.....如果不匹配,它将抛出上述错误...如果您已卸载,请确保删除上述路径文件夹C:\Users"Your User Name".dotnet\ 并再次重新安装....它将为我工作

      【讨论】:

        猜你喜欢
        • 2019-09-26
        • 2018-05-27
        • 1970-01-01
        • 2013-09-23
        • 2018-04-27
        • 1970-01-01
        • 1970-01-01
        • 2013-01-21
        • 2014-10-03
        相关资源
        最近更新 更多