发生了致命错误。找不到所需的库 hostfxr.dll

Sil*_*oJa 49 visual-studio

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

Description: A .NET Core application failed.
Application: SamplerSLEX.exe
Path: C:\Users\admin\Downloads\TesterSLEX\TesterSLEX\SamplerSLEX.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:\Users\admin\Downloads\TesterSLEX\TesterSLEX\].
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].
Run Code Online (Sandbox Code Playgroud)

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

WPF netcoreapp3.0

小智 52

除了 Ajith 的回答之外,还可以在此处在 Visual Studio 2019 中选择“部署模式:自包含”:

Visual Studio 中的图形用户界面

  • 奇怪的是,自给自足并没有为我解决这个问题。如果您单击“显示所有设置”->“文件发布选项”,我还必须选中“生成单个文件”和“启用 ReadyToRun 编译”,然后它就可以工作了。 (4认同)

小智 21

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

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

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.12-windows-hosting-bundle-installer

  • 在 2021 年,这是最简单、最简单的解决方案。 (4认同)

Aji*_*ith 17

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

对此的解决方案是发布具有自包含部署模式的应用程序。

使用以下命令从命令行发布

dotnet publish -c Release -r <RID> --self-contained true
Run Code Online (Sandbox Code Playgroud)

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

  • 我正在使用“msbuild”而不是“dotnetpublish”构建我的程序,您是否知道打开“自包含部署模式”的标志? (3认同)

Jit*_*mar 5

从错误消息来看,如果这是一个依赖于框架的应用程序

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].
Run Code Online (Sandbox Code Playgroud)

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

C:\Program Files\dotnet OR C:\Program Files (x86)\dotnet
Run Code Online (Sandbox Code Playgroud)

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